#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)

bool judgeTriple(int tmp2[], int count){
  if(count==4)
    return true;
  for(int i=1; i<=7; i++){
    if(tmp2[i]>=1 && tmp2[i+1]>=1 && tmp2[i+2]>=1){
      tmp2[i]--;
      tmp2[i+1]--;
      tmp2[i+2]--;
      if(judgeTriple(tmp2,count+1))
	return true;
      tmp2[i]++;
      tmp2[i+1]++;
      tmp2[i+2]++;
    }
  }
  REP(i,10){
    if(tmp2[i]>=3){
      tmp2[i]-=3;
      if(judgeTriple(tmp2,count+1))
	return true;
      tmp2[i]+=3;
    }
  }
  return false;
}

bool isEnd(int tmp[]){
  REP(i,10){
    if(tmp[i]>=5)
      return false;
  }
  // remove head
  for(int i=1; i<10; i++){
    if(tmp[i]>=2){
      tmp[i]-=2;
      if( judgeTriple(tmp,0) )
	return true;
      tmp[i]+=2;
    }
  }
  return false;
}

int main()
{
  string str;
  while(cin>>str){
    int nums[10];
    memset(nums, 0, sizeof(nums));

    REP(i,str.size())
      nums[str[i]-'0']++;

    vector<int> res;

    for(int i=1; i<=9; i++){
      int tmp[10];
      memcpy(tmp, nums, sizeof(nums));
      tmp[i]++;

      if(isEnd(tmp)){
	res.push_back(i);
      }
    }

    if(res.empty())
      cout << "0" << endl;
    else{
      bool first=true;
      IREP(it,res){
	if(!first)
	  cout << " ";
	first = false;
	cout << *it;
      }
      cout << endl;
    }
  }

  return 0;
}