#include <iostream>
#include <vector>
using namespace std;

bool check( vector<int> hai, int cnt ) {

  if ( cnt == 0 ) return true;

  for ( int i = 0; i < 9; i++ ) {
    if ( hai[i] >= 3 ) {
      hai[i]-=3;
      if ( check( hai, cnt-1 ) ) return true;
      hai[i]+=3;
    }
  }

  for ( int i = 0; i < 7; i++ ) {
    if ( hai[i] * hai[i+1] * hai[i+2] != 0 ) {
      hai[i]--;
      hai[i+1]--;
      hai[i+2]--;
      if ( check( hai, cnt-1 ) ) return true;
      hai[i]++;
      hai[i+1]++;
      hai[i+2]++;
    }
  }

  return false;

}

int main() {

  while(true) {

  vector<int> hai;
  for ( int i = 0; i < 9; i++ ) {
    hai.push_back(0);
  }

  for ( int i = 0; i < 13; i++ ) {
    char input;
    cin >> input;
    if ( cin.eof() ) return 0;
    hai[input-'1']++;
  }

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

    if ( hai[i] < 4 ) {
      hai[i]++;

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

	if ( hai[j] >= 2 ) {
	  hai[j] -= 2;

	  if ( check( hai, 4 ) ) {
	    if ( flag == false ) {
	      cout << " ";
	    }
	    cout << i+1;
	    flag = false;
	    hai[j] += 2;
	    break;
	  }

	  hai[j] += 2;

	}

      }

      hai[i]--;

    }

  }

  if ( flag ) cout << "0";
  cout << endl;

  }

  return 0;
}