#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  string line;
  while(cin>>line){
    int c[9]={0};
    REP(i,13){
      c[line[i]-'1']++;
    }
    bool out[9]={false};
    REP(i,9){
      if(c[i]>=4) continue;
      int tmp[9];
      REP(j,9){
        REP(k,9) tmp[k] = c[k];
        tmp[i]++;
        if(tmp[j]<2) continue;
        tmp[j]-=2;
        REP(k,7){
          while(tmp[k]%3!=0){
            tmp[k]--;
            tmp[k+1]--;
            tmp[k+2]--;
          }
        }
        bool outp=true;
        REP(k,9) if(tmp[k]%3!=0||tmp[k]<0) outp = false;
        if(outp){
          out[i]=true;
          break;
        }
      }
    }

    bool f=false;
    REP(i,9)if(out[i]){
      if(f) cout<<" ";
      f = true;
      cout<<i+1;
    }
    if(!f) cout<<0;
    cout<<endl;
  }
  return 0;
}