#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include <vector>
#include <map>
#include<cstdlib>


using namespace std;

bool Check2(vector<int> solution)
{
    for (int i = 1; i <= 9; i++)
    {
        if(solution[i] > 2)
        {
            solution[i] -= 3;
        }
        
        while(solution[i - 1] > 0) //667
        {
            solution[i - 1]--;
            solution[i]--;
            solution[i+1]--;
            
            if(solution[i] < 0 || solution[i + 1] < 0)
            {
                return 0;
            }
        }
    }
    
    return 1;
}

bool Check(vector<int> solution)
{
    bool isAdd;

    for (int i = 1; i <= 9; i++)
    {
        if(solution[i] > 1) // check if there are same numbers bigger than 1, like 99 or 777
        {
            solution[i] -= 2;
            
            isAdd = Check2(solution);
            
            solution[i] += 2; //repeat from above
            
            if(isAdd)
            {
                return 1;
            }
        }
    }
    
    return 0;
}

int main()
{
    string str;
    
    while(cin>>str)
    {
        vector<int> solution(14); // to save the number for new string
        
        bool flag = 0; //judge if there is a number can be added to str
        
        for (int i = 0; i < 13; i++)
        {
            //calculate the frequent rate of numbers, and start to formulate the rules to program
            solution[str[i] - '0']++; //save the frequent rate, base on rules, can not above 5
        }
        
        for (int i = 1; i <= 9 ; i++)
        {
            if(solution[i]>3)
            {
                continue;  // solution[i] == 0 or 1 or 2 or 3
            }
            
            solution[i]++; // try to add 1(frequent rate) for each number
            
            if(Check(solution))
            {
                if(flag)
                {
                    cout<<" ";
                }
                
                cout<<i;
                
                flag = 1;
            }
            
            solution[i]--;
        }
        
        if(!flag)
        {
            cout<<0<<endl;
        }
        else
        {
            cout<<endl;
        }
    }
    return 0;
}