#include <iostream>
#include <string>

using namespace std;

//[³DæTõ
bool dfs(int hand[9],int k) {

  //cout << "dfs: ";
  //for(int i=0;i<9;i++) cout << hand[i] << " ";
  //cout << endl;
  //cout << k << endl;

  //9ÜÅ|C^ðißé±ÆªoêÎ¬÷
  if(k>=9) return true;

  //»ÌÌèDª0Èç³µÄÌÖ
  if(hand[k]==0) return dfs(hand,k+1);

  //»ÌÌèDª3ÈãÈçÆè ¦¸»êçðyAÉµÄÝéB_¾Á½ç«µßµÄð±s
  if(hand[k]>=3) {

    hand[k]-=3;

    if(dfs(hand,k)) return true;

    hand[k]+=3;

  }

  //±êæèãÍAAÔÌðyAÉ·éµ©È¢

  //7ÜÅ|C^ðißÄ¢½çcèÌÍ8,9µ©È¢B±êÍsÂ\
  if(k>=7) return false;

  //TõÌ|C^©çEÉ3ÂÌðyAÉ·é(µ©È¢)
  //Å«È¢ÈçI¹
  for(int i=k+1;i<k+3;i++) {

    if(hand[i]==0) return false;

  }

  for(int i=k;i<k+3;i++) hand[i]--;

  //Tõð±s
  if(dfs(hand,k)) return true;

  //_¾Á½ç«µßµÄI¹
  for(int i=k;i<k+3;i++) hand[i]++;

  return false;

}

int main() {

  string buf;

  int hand[9];

  int flag;
  int ans;


  while(cin >> buf) {

    ans=0;

    for(int i=0;i<9;i++) {

      flag=1;

      for(int j=0;j<9;j++) hand[j]=0;

      //hand[i]ÉÍiª¢­ÂüÁÄ¢é©ði[·é
      for(int j=0;j<13;j++) {
      
	hand[(buf[j]-1)-48]++;

      }

      buf[13]=i+1+48;

      hand[(buf[13]-1)-48]++;
      //for(int j=0;j<9;j++) cout << hand[j] << " ";
      //cout << endl;
      //5ÂÈã¯¶ªüÁÄ¢½ç_
      if(hand[(buf[13]-1)-48]>=5) {

	hand[(buf[13]-1)-48]--;

	continue;

      }

      //Æè ¦¸¯¶2Âðæè«AcèÌèDÅpYð®¬Å«é©ð»è·é(STõH)
      for(int j=0;j<9;j++) {

	if(hand[j]>=2) {

	  hand[j]-=2;

	  //for(int k=0;k<9;k++) cout << hand[k] << " ";
	  //cout << endl;

	  if(dfs(hand,0)==true) {

	    if(ans==0) cout << i+1;

	    else cout << " " << i+1;

	    ans++;

	    break;

	  }

	  hand[j]+=2;

	}

      }

	hand[(buf[13]-1)-48]--;

    }

    if(ans==0) cout << "0";

    cout << endl;

  }

  return 0;

}