def check(x,j=1):

    if sum(x)==0: return True

    for i in range(j,10):

        y = x[:]

        if y[i]>=3:

            y[i] -= 3

            if check(y,i): return True

        y = x[:]

        if i<8 and y[i]>0 and y[i+1]>0 and y[i+2]>0:

            y[i] -= 1

            y[i+1] -= 1

            y[i+2] -= 1

            if check(y,i): return True

    return False



while True:

    c = [0]*10

    try:

        for e in map(int,input()):

            c[e] += 1

    except:

        break



    f = False

    for i in range(1,10):

        c1=c[:]

        if c1[i]>=4: continue

        else: c1[i]+=1

        atama = [j for j,e in enumerate(c1) if e>=2]

        for e in atama:

            c1[e]-=2

            if check(c1):

                f = True

                print(i, end=' ')

                break

            c1[e]+=2

    if f: print()

    else: print(0)
def check(x,j=1):

    if sum(x)==0: return True

    for i in range(j,10):

        if x[i]>0:break

    y = x[:]

    if y[i]>=3:

        y[i] -= 3

        if check(y,i): return True

    y = x[:]

    if i<8 and y[i]>0 and y[i+1]>0 and y[i+2]>0:

        y[i] -= 1

        y[i+1] -= 1

        y[i+2] -= 1

        if check(y,i): return True

    return False



while True:

    c = [0]*10

    try:

        for e in map(int,input()):

            c[e] += 1

    except:

        break



    f = False

    for i in range(1,10):

        c1=c[:]

        if c1[i]>=4: continue

        else: c1[i]+=1

        atama = [j for j,e in enumerate(c1) if e>=2]

        for e in atama:

            c1[e]-=2

            if check(c1):

                f = True

                print(i, end=' ')

                break

            c1[e]+=2

    if f: print()

    else: print(0)
def check(x, j=1):
    if sum(x) == 0:
        return True
    for i in range(j, 10):
        y = x[:]
        if y[i] >= 3:
            y[i] -= 3
            if check(y, i):
                return True
        y = x[:]
        if i < 8 and y[i] > 0 and y[i + 1] > 0 and y[i + 2] > 0:
            y[i] -= 1
            y[i + 1] -= 1
            y[i + 2] -= 1
            if check(y, i):
                return True
    return False


while True:
    c = [0] * 10
    try:
        for e in map(int, input()):
            c[e] += 1
    except:
        break
    f = False
    for i in range(1, 10):
        c1 = c[:]
        if c1[i] >= 4:
            continue
        else:
            c1[i] += 1
        atama = [j for j, e in enumerate(c1) if e >= 2]
        for e in atama:
            c1[e] -= 2
            if check(c1):
                f = True
                print(i, end=" ")
                break
            c1[e] += 2
    if f:
        print()
    else:
        print(0)

def check(x, j=1):
    if sum(x) == 0:
        return True
    for i in range(j, 10):
        if x[i] > 0:
            break
    y = x[:]
    if y[i] >= 3:
        y[i] -= 3
        if check(y, i):
            return True
    y = x[:]
    if i < 8 and y[i] > 0 and y[i + 1] > 0 and y[i + 2] > 0:
        y[i] -= 1
        y[i + 1] -= 1
        y[i + 2] -= 1
        if check(y, i):
            return True
    return False


while True:
    c = [0] * 10
    try:
        for e in map(int, input()):
            c[e] += 1
    except:
        break
    f = False
    for i in range(1, 10):
        c1 = c[:]
        if c1[i] >= 4:
            continue
        else:
            c1[i] += 1
        atama = [j for j, e in enumerate(c1) if e >= 2]
        for e in atama:
            c1[e] -= 2
            if check(c1):
                f = True
                print(i, end=" ")
                break
            c1[e] += 2
    if f:
        print()
    else:
        print(0)

-        y = x[:] -        if y[i] >= 3: -            y[i] -= 3 -            if check(y, i): -                return True -        y = x[:] -        if i < 8 and y[i] > 0 and y[i + 1] > 0 and y[i + 2] > 0: -            y[i] -= 1 -            y[i + 1] -= 1 -            y[i + 2] -= 1 -            if check(y, i): -                return True +        if x[i] > 0: +            break +    y = x[:] +    if y[i] >= 3: +        y[i] -= 3 +        if check(y, i): +            return True +    y = x[:] +    if i < 8 and y[i] > 0 and y[i + 1] > 0 and y[i + 2] > 0: +        y[i] -= 1 +        y[i + 1] -= 1 +        y[i + 2] -= 1 +        if check(y, i): +            return True