#include <iostream>
#include <vector>
using namespace std;

//#pragma comment(linker, "/STACK:400000000")

#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pb push_back
#define sz size()
#define vi vector<int>

string in;
vi a;

int dfs(vi v,int rest){
    if(rest==0)return 1;
    if(rest==14){
        rep(i,9)if(v[i]>=2){
            vi w=v;
            w[i]-=2;
            if(dfs(w,12))return 1;
        }
        return 0;
    }
    rep(i,9)if(v[i]>=3){
        vi w=v;
        w[i]-=3;
        if(dfs(w,rest-3))return 1;
    }
    rep(i,7)if(v[i] && v[i+1] && v[i+2]){
        vi w=v;
        w[i]--; w[i+1]--; w[i+2]--;
        if(dfs(w,rest-3))return 1;
    }
    return 0;
}

int main(){
	while(cin>>in){
        vi v(9,0),ans;
        rep(i,13)v[in[i]-'1']++;
        rep(i,9){
            if(v[i]==4)continue;
            vi w=v;
            w[i]++;
            if(dfs(w,14))ans.pb(i);
        }
        if(ans.sz==0)cout<<0<<endl;
        else{
            rep(i,ans.sz)cout<<ans[i]+1<<( i!=ans.sz-1?" ":"\n");
        }
    }
}