using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public string s { get; set; }
    public int c { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string s;
        for (; (s = Console.ReadLine()) != null;)
        {
            var a = new int[9];
            for (int i = 0; i < 13; i++) a[int.Parse(s[i].ToString()) - 1]++;
            var ret = new List<int>();
            for (int i = 0; i < 9; i++)
            {
                a[i]++;
                if (a[i] >= 5) { a[i]--; continue; }
                for (int j = 0; j < 9; j++)
                {
                    if (a[j] >= 2)
                    {
                        var b = new int[9];
                        Array.Copy(a, b, 9);
                        b[j] -= 2;
                        var ww = putA(b);
                        var x = check(ww);
                        if (x && goBfs(ww, 12)) { ret.Add(i); goto next; }
                    }
                }
                next:;
                a[i]--;
            }
            print(ret);
        }
    }
    public static void print(List<int> a)
    {
        var ac = a.Count();
        if (ac == 0) Console.WriteLine(0);
        for (int i = 0; i < ac; i++)
            if (i == ac - 1) Console.WriteLine(a[i] + 1);
            else Console.Write("{0} ", a[i] + 1);
    }
    public static bool goBfs(string s, int c)
    {
        var st = new Stack<P>();
        st.Push(new P { s = s, c = c });
        while (st.Count() > 0)
        {
            var x = st.Pop();
            if (x.c == 0) return true;
            if (!check(x.s)) continue;
            var a = getA(x.s);

            for (int i = 0; i <= 6; i++)
            {
                if (a[i] >= 1 && a[i + 1] >= 1 && a[i + 2] >= 1)
                {
                    a[i]--; a[i + 1]--; a[i + 2]--;
                    var ww = putA(a);
                    st.Push(new P { s = ww, c = x.c - 3 });
                    a[i]++; a[i + 1]++; a[i + 2]++;
                }
            }
            for (int i = 0; i <= 8; i++)
                if (a[i] >= 3)
                {
                    a[i] -= 3;
                    var ww = putA(a);
                    st.Push(new P { s = ww, c = x.c - 3 });
                    a[i] += 3;
                }
        }
        return false;
    }
    public static bool check(string s)
    {
        var ng = new string[] { "010", "020", "0110", "0120", "0210", "0220" };
        var ngL3 = new string[] { "110", "120", "210", "220" };
        var ngL2 = new string[] { "10", "20" };
        var ngr2 = new string[] { "01", "02" };
        var ngr3 = new string[] { "011", "012", "021", "022" };
        var L2 = s.Substring(0, 2); var L3 = s.Substring(0, 3);
        var r2 = s.Substring(7); var r3 = s.Substring(6);
        foreach (var x in ng)
            if (s.Contains(x)) return false;
        foreach (var x in ngL3)
            if (x == L3) return false;
        foreach (var x in ngL2)
            if (x == L2) return false;
        foreach (var x in ngr3)
            if (x == r3) return false;
        foreach (var x in ngr2)
            if (x == r2) return false;
        return true;
    }

    public static int[] getA(string s)
    {
        var ret = new int[9];
        for (int i = 0; i < 9; i++) ret[i] = int.Parse(s[i].ToString());
        return ret;
    }
    public static string putA(int[] a)
    {
        var ret = "";
        for (int i = 0; i < 9; i++) ret += a[i].ToString();
        return ret;
    }
}



Measured memory_bytes: 11100