#include <bits/stdc++.h>
using namespace std;

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

inline void debug(int*hand) {
  rep (i, 9) {
    cout << "[" << (i+1) << "] * " << hand[i] << ", ";
  } cout << endl;
}

bool body(int*hand) {
  {
    bool ac = true;
    rep (i, 9) if (hand[i]) ac = false;
    if (ac) return true;
  }
  rep (i, 9 - 2) {
    if (hand[i] && hand[i+1] && hand[i+2]) {
      hand[i]--;
      hand[i+1]--;
      hand[i+2]--;
      bool b = body(hand);
      hand[i]++;
      hand[i+1]++;
      hand[i+2]++;
      if (b) return true;
    }
  }
  rep (i, 9) {
    if (hand[i] >= 3) {
      hand[i] -= 3;
      bool b = body(hand);
      hand[i] += 3;
      if (b) return true;
    }
  }
  return false;
}

bool solve(int*hand) {
  rep (i, 9) {
    if (hand[i] >= 5) return false;
  }

  rep (head, 9) {
    if (hand[head] < 2) continue;
    hand[head] -= 2;
    bool b = body(hand);
    hand[head] += 2;
    if (b) return true;
  }
  return false;
}

int main() {

  string s;
  loop {
    cin >> s; if (!cin) break;
    int hand[9] = {0};
    rep (i, s.size()) {
      hand[s[i] - '1']++;
    }

    vi ans;
    rep (i, 9) {
      hand[i]++;
      if (solve(hand)) ans.push_back(i + 1);
      hand[i]--;
    }

    if (ans.size() == 0) {
      cout << 0 << endl;
    } else {
      cout << ans << endl;
    }
  }

  return 0;
}