#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

bool solve(vector<int> in){
  rep(i,9){
    int cnt = 0;
    while(in[i]){
      cnt++;
      if(in[i]>=3)in[i]-=3;
      else if(i<7 && in[i]&&in[i+1]&&in[i+2]){
	      in[i]--;in[i+1]--;in[i+2]--;
      }
      if(cnt==6)break;
    }
  }
  bool h = true;
  rep(i,9){
    if(in[i])h=false;
  }
  return h;
}

int main(void){
  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 h=false;
        if(solve(in)){h=true;out.push_back(i+1);}
        in[j]+=2;
        if(h)break;
      }
      in[i]--;
    }
    if(out.size()){
      rep(i,out.size()-1)cout<<out[i]<<" ";
      cout<<out[out.size()-1]<<endl;
    }else cout<<0<<endl;
  }
}