#include<iostream>
#include<cstring>
#include<string>
using namespace std;

bool check( int *counts ){
    int cp[10];
    for( int i=0; i<10; i++ )
        cp[i] = counts[i];
    for( int i=0; i<10; i++ ){
        while( cp[i] >= 3 )
            cp[i] -= 3;
        while( i+2<10 && cp[i]>0 && cp[i+1]>0 && cp[i+2]>0 ){
            cp[i]--;
            cp[i+1]--;
            cp[i+2]--;
        }
    }
    for( int i=0; i<10; i++ ){
        if( cp[i] != 0 ){
            return false;
        }
    }
    return true;
}

int main(){
    int counts[10];
    string in;
    while( cin >> in ){
        memset(counts, 0, sizeof(counts));
        for( int i=0; i<13; i++ ){
            counts[in[i]-'0']++;
        }
        
        bool end = false;
        for( int i=1; i<10; i++ ){
            if( counts[i] > 4 ){
                cout << "0" << endl;
                end = true;
            }
        }
        if(end) continue;

        bool first = true;
        for( int i=1; i<10; i++ ){
            if( counts[i] >= 4 )    continue;
            counts[i]++;
            for( int j=1; j<10; j++ ){
                if( counts[j] >= 2 ){
                    counts[j] -= 2;
                    if( check(counts) ){
                        if( first )
                            first = false;
                        else
                            cout << " ";
                        cout << i;
                        counts[j] += 2;
                        break;
                    }
                    counts[j] += 2;
                }
            }
            counts[i]--;
        }
        if(first)
            cout << "0";
        cout << endl;
    }
    return 0;
}