#include<iostream>
#include<algorithm>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)

using namespace std;

string line;
int cnt[10];

bool isOk(int *ccnt)
{
  REP(i,1,10)
    {
      if(ccnt[i] == 0)continue;
      if(ccnt[i] == 1)
	{
	  if(i+2 <= 9 && ccnt[i]-1 >= 0 && ccnt[i+1]-1 >= 0 && ccnt[i+2]-1 >= 0)
	    {
	      ccnt[i]--,ccnt[i+1]--,ccnt[i+2]--;
	    }
	}
      else if(ccnt[i] == 2)
	{
	  if(i+2 <= 9 && ccnt[i]-2 >= 0 && ccnt[i+1]-2 >= 0 && ccnt[i+2]-2 >= 0)
	    {
	      ccnt[i]-=2,ccnt[i+1]-=2,ccnt[i+2]-=2;
	    }
	}
      else if(ccnt[i] == 3)
	{
	  ccnt[i] -= 3;
	}
      else if(ccnt[i] == 4)
	{
	  if(i+2 <= 9 && ccnt[i]-1 >= 0 && ccnt[i+1]-1 >= 0 && ccnt[i+2]-1 >= 0)
	    {
	      ccnt[i]-=4,ccnt[i+1]--,ccnt[i+2]--;
	    }
	}
      if(ccnt[i] != 0)return false;
    }
  return true;
}

bool check(int piece)
{
  cnt[piece]++;
  int ccnt[10];
  REP(i,1,10)
    {//頭を決める
      if(cnt[i] <= 1)continue;
      rep(j,10)ccnt[j] = cnt[j];
      ccnt[i] -= 2;
      if(isOk(&ccnt[0]))
	{
	  cnt[piece]--;
	  return true;
	}
    }
  cnt[piece]--;
  return false;
}

void compute()
{
  rep(i,10)cnt[i] = 0;
  rep(i,13)cnt[line[i]-'0']++;
  bool ok = false;
  REP(i,1,10)
    {
      if(cnt[i]+1 >= 5)continue;

      if(check(i))
	{
	  if(ok)cout << " ";
	  ok = true;
	  cout << i;
	}
    }
  if(!ok)cout << 0 << endl;
  else   cout << endl;
}

int main()
{
  while(cin >> line)
    compute();    
  return 0;
}