#include<iostream>
using namespace std;

bool agari(int num[]){
  for(int head = 1;head<10;head++){
    if(num[head]>=2){
      int hands[12] = {0};
      for(int i = 1;i<10;i++)
	hands[i] = num[i];
      hands[head]-=2;
      bool agari = true;
      for(int i=0;i<10;i++)
	while(hands[i]%3)
	  for(int j=0;j<3;j++){
	    hands[i+j]--;
	    if(hands[i+j]<0)
	      agari = false;
	  }
      if(agari)
	return true;
    }
  }
  return false;
}

int main(){
  long long hand;
  while(cin>>hand){
    int num[10] = {0};
    for(;hand>0;hand/=10){
      num[hand%10]++;
    }
    bool tenpai = false;
    for(int i=1;i<10;i++){
      if (num[i]<4){
	num[i]++;
	if(agari(num)){
	  if(tenpai)
	    cout<<" ";
	  cout<<i;
	  tenpai = true;
	}
	num[i]--;
      }
    }
    if(!tenpai)
      cout<<0;
    cout<<endl;
  }
  return 0;
}