#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int p[13];

bool check(int i, bool a){
  if(i == 10) return true;
  if(p[i] == 0) return check(i+1,a);
  if(p[i] >= 1){
    if(p[i+1] != 0 && p[i+2] != 0){
      p[i]--; p[i+1]--; p[i+2]--;
      if(check(i,a)){
	p[i]++; p[i+1]++; p[i+2]++;
	return true;
      }
      p[i]++; p[i+1]++; p[i+2]++;
    }
  }
  if(p[i] >= 2){
    if(!a){
      p[i]-=2;
      if(check(i,true)){
	p[i]+=2;
	return true;
      }
      p[i]+=2;
    }
  }
  if(p[i] >= 3){
    p[i] -= 3;
    if(check(i,a)){
      p[i] += 3;
      return true;
    }
    p[i] += 3;
  }
  return false;
}

int main(){
  string str;
  while(cin>>str){
    bool f = true;
    memset(p, 0, sizeof(p));
    REP(i,13) p[str[i] - '0']++;
    REP(i,9){
      if(p[i+1] < 4){
	p[i+1]++;
	if(check(1,false)){
	  if(f){
	    f = false;
	  }else{
	    putchar(' ');
	  }
	  printf("%d",i+1);
	}
	p[i+1]--;
      }
    }	     
    if(f) printf("0");
    puts("");
  }
  return 0;
}