#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
bool solve(vector<int>in){
  rep(k,9){
    int co=0;
    while(in[k]){
      co++;
      if(in[k]>=3)in[k]-=3;
      else if(k<7&&in[k]&&in[k+1]&&in[k+2]){
	in[k]--;in[k+1]--;in[k+2]--;
      }
      if(co==6)break;
    }
  }
  bool h=true;
  rep(k,9)if(in[k])h=false;
  return h;
}
int main(){
  string s;
  while(cin>>s){
    vector<int>in(9);
    vector<int>out;
    rep(i,s.size())in[s[i]-'1']++;
    rep(i,9){
      if(in[i]==4)continue;
      in[i]++;
      rep(j,9){
	if(in[j]<2)continue;
	in[j]-=2;bool hh=false;
	if(solve(in)){hh=true;out.pb(i+1);}
	in[j]+=2;
	if(hh)break;
      }
      in[i]--;
    }
    if(out.size()){
      rep(i,out.size()-1)cout<<out[i]<<" ";
      cout<<out[out.size()-1]<<endl;
    }else cout<<0<<endl;
  }
}