#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

vector<int> del1(vector<int> v) {
  REP(j,9) {
    if (count(ALL(v), j) >= 3) {
      v.erase(find(ALL(v),j));
      v.erase(find(ALL(v),j));
      v.erase(find(ALL(v),j));
    }
  }
  return v;
}
vector<int> del2(vector<int> v) {
  REP(j,7) {
    while(true) {
      vector<int>::iterator i1 = find(ALL(v),j), i2 = find(ALL(v),j+1),i3 = find(ALL(v),j+2);
      if (i1!=v.end()&&i2!=v.end()&&i3!=v.end()) {
        v.erase(i1); v.erase(i2-1); v.erase(i3-2);
      } else {
        break;
      }
    }
  }
  return v;
}

bool func(vector<int> v) {
  REP(i,9) {                         
    vector<int> vv(v);
    if (count(ALL(vv), i) < 2) continue;
    vv.erase(find(ALL(vv),i));
    vv.erase(find(ALL(vv),i));

    vector<int> vvv(vv);  
    vvv = del1(vvv);
    vvv = del2(vvv);

    if (vvv.size()==0)
      return true;
    vvv = vv;
  
    vvv = del2(vvv);
  
    vvv = del1(vvv);
   
    if (vvv.size()==0)
      return true;
  }
  return false;
}

int main() {
  string s;
  while(cin>>s) {

    vector<int> v(13);
    REP(i,13)
      v[i] = s[i] - '1';
    
    int f = 0;
    REP(i,9) {
      if (count(ALL(v), i)==4) continue;
      vector<int> vv(v);
      vv.push_back(i);
      sort(ALL(vv));
      if (func(vv)) {
        if (f)
          cout << " ";
        cout << i + 1;
        f = 1;
      }
    }
    if (f==0) cout << 0;
    cout << endl;
  }
}