#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int v[14];

int t[][3]={
    {0,0,0},
    {1,1,1},
    {2,2,2},
    {3,3,3},
    {4,4,4},
    {5,5,5},
    {6,6,6},
    {7,7,7},
    {8,8,8},

    {0,1,2},
    {1,2,3},
    {2,3,4},
    {3,4,5},
    {4,5,6},
    {5,6,7},
    {6,7,8}
};

bool dfs(vector<int> rest, int depth){
    if(depth==4){
        int ze=0, tw=0;
        for(int x:rest)if(x==0)ze++;else if(x==2)tw++;
        return ze==8 && tw==1;
    }
    bool res=false;
    rep(i,16){
        for(int x:t[i])rest[x]--;
        for(int x:rest)if(x<0)goto UNDO;
        if(dfs(rest,depth+1)){
            res=true;
            goto END;
        }
    UNDO:;
        for(int x:t[i])rest[x]++;
    }
 END:;
    return res;
}

vector<int> solve(){
    vector<int> ans;
    vector<int> rest(9);
    rep(i,13)rest[v[i]]++;
    rep(i,9){
        if(rest[i]!=4){
            rest[i]++;
            if(dfs(rest,0))ans.push_back(i+1);
            rest[i]--;
        }
    }
    return ans;
}

int main(){
    char buf[20];
    while(cin>>buf){
        rep(i,13)v[i]=buf[i]-'0'-1;
        vector<int> ans=solve();
        if(ans.size()){
            rep(i,ans.size()){
                cout<<ans[i];
                if(i==ans.size()-1)cout<<endl;
                else cout<<" ";
            }
        } else cout<<0<<endl;
    }
}