#include <iostream> 
#include <sstream> 
#include <iomanip> 
#include <algorithm> 
#include <cmath> 
#include <string> 
#include <vector> 
#include <list> 
#include <queue> 
#include <stack> 
#include <set> 
#include <map> 
#include <bitset> 
#include <numeric> 
#include <climits> 
#include <cfloat> 
using namespace std;

bool solve(vector<int> a)
{
    int n = a.size();
    if(n == 0)
        return true;

    if(n == 14){
        sort(a.begin(), a.end());
        for(int i=0; i<13; ++i){
            if(a[i] == a[i+1]){
                vector<int> b = a;
                b.erase(b.begin()+i, b.begin()+i+2);
                if(solve(b))
                    return true;
            }
        }
        return false;
    }

    if(a[0] == a[1] && a[1] == a[2]){
        a.erase(a.begin(), a.begin()+3);
        return solve(a);
    }

    vector<int>::iterator it;
    it = find(a.begin(), a.end(), a[0]+1);
    if(it == a.end())
        return false;
    a.erase(it);
    it = find(a.begin(), a.end(), a[0]+2);
    if(it == a.end())
        return false;
    a.erase(it);
    a.erase(a.begin());

    return solve(a);
}

int main()
{
    for(;;){
        string s;
        if(!(cin >> s))
            return 0;

        vector<int> a(13);
        for(int i=0; i<13; ++i)
            a[i] = s[i] - '0';

        vector<int> ret;
        for(int i=1; i<=9; ++i){
            vector<int> b = a;
            b.push_back(i);
            if(count(b.begin(), b.end(), i) > 4)
                continue;

            if(solve(b))
                ret.push_back(i);
        }

        if(ret.size() == 0){
            cout << 0 << endl;
        }else{
            cout << ret[0];
            for(unsigned i=1; i<ret.size(); ++i)
                cout << ' ' << ret[i];
            cout << endl;
        }
    }
}