#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;

bool find_torio(int* ary, int rest){
  if(rest==0) return true;
  for(int i=0;i<7;i++){
    if(ary[i]>0&&ary[i+1]&&ary[i+2]>0){
      int ary2[9]; copy(ary,ary+9,ary2);
      ary2[i]--; ary2[i+1]--; ary2[i+2]--;
      if(find_torio(ary2,rest-1)) return true;
    }
  }
  for(int i=0;i<9;i++){
    if(ary[i]>=3){
      int ary2[9]; copy(ary,ary+9,ary2);
      ary2[i]-=3;
      if(find_torio(ary2,rest-1)) return true;
    }
  }
  return false;
}

int main(){
  char s[16];
  while(scanf("%s",s)>0){
    int a[9]{0};
    set<int> atari;
    for(char c:s)
      a[(int)(c-'1')]++;
    for(int i=0;i<9;i++){//当たり牌
      if(a[i]==4) continue;
      int b[9]; copy(a,a+9,b);
      b[i]++;
      for(int j=0;j<9;j++){//頭
	if(b[j]<2) continue;
	int c[9]; copy(b,b+9,c);
	c[j]-=2;
	if(find_torio(c,4))
	  atari.insert(i);
      }
    }
    int count=0;
    for(int i:atari){
      if(++count==atari.size())
	printf("%d\n",i+1);
      else
	printf("%d ",i+1);
    }
    if(count==0) printf("0\n");
  }
}