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

class Program
{
    public static bool ShuntsuLeft(int[] a, int i, bool atama)
    {
        var b = (int[])a.Clone();
        if (i >= 2 && b[i - 1] >= 1 && b[i - 2] >= 1)
        {
            b[i]--;
            b[i - 1]--;
            b[i - 2]--;
            return Check(b, atama);
        }
        else
        {
            return false;
        }
    }
    public static bool ShuntsuMid(int[] a, int i, bool atama)
    {
        var b = (int[])a.Clone();
        if (i >= 1 && i <= 7 && b[i - 1] >= 1 && b[i + 1] >= 1)
        {
            b[i]--;
            b[i - 1]--;
            b[i + 1]--;
            return Check(b, atama);
        }
        else
        {
            return false;
        }
    }
    public static bool ShuntsuRight(int[] a, int i, bool atama)
    {
        var b = (int[])a.Clone();
        if (i <= 6 && b[i + 1] >= 1 && b[i + 2] >= 1)
        {
            b[i]--;
            b[i + 1]--;
            b[i + 2]--;
            return Check(b, atama);
        }
        else
        {
            return false;
        }
    }

    public static bool Shuntsu(int[] a, int i, bool atama)
    {
        return ShuntsuLeft(a, i, atama) || ShuntsuMid(a, i, atama) || ShuntsuRight(a, i, atama);
    }

    public static bool Janto(int[] a, int i, bool atama)
    {
        var b = (int[])a.Clone();
        if (!atama)
        {
            b[i] -= 2;
            return Check(b, true);
        }
        else
        {
            return false;
        }
    }

    public static bool Kotsu(int[] a, int i, bool atama)
    {
        var b = (int[])a.Clone();
        b[i] -= 3;
        return Check(b, atama);
    }

    public static bool Check(int[] a, bool atama)
    {
        if (a.Where(x => x >= 5).Count() >= 1)
        {
            return false;
        }
        for (int i = 0; i < 9; i++)
        {
            if (a[i] == 1)
            {
                return Shuntsu(a, i, atama);
            }
        }

        for (int i = 0; i < 9; i++)
        {
            if (a[i] == 2)
            {
                return Shuntsu(a, i, atama) || Janto(a, i, atama);
            }
        }

        for (int i = 0; i < 9; i++)
        {
            if (a[i] >= 3)
            {
                return Shuntsu(a, i, atama) || Janto(a, i, atama) || Kotsu(a, i, atama);
            }
        }
        return true;
    }

    public static void Main()
    {
        string s;
        while ((s = Console.ReadLine()) != null)
        {
            var a = new int[9];
            foreach (var item in s)
            {
                a[int.Parse(item.ToString()) - 1]++;
            }
            var list = new List<int>();
            for (int i = 0; i < 9; i++)
            {
                var b = (int[])a.Clone();
                b[i]++;
                if (Check(b, false))
                {
                    list.Add(i + 1);
                }
            }
            if (list.Count == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(string.Join(" ", list));
            }
        }
    }
}


Measured memory_bytes: 16196