#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

bool valid(vi& v)
{
  for (int i = 1; i < 10; i++) {
    if (v[i] > 4)
      return false;
  }
  return true;
}

bool zero(vi& v)
{
  for (int i = 1; i < 10; i++) {
    if (v[i]) return false;
  }
  return true;
}

bool check(vi& v)
{
  if (zero(v))
    return true;
  for (int i = 1; i < 10; i++) {
    if (v[i] >= 3) {
      v[i] -=3;
      if (check(v))
        return true;
      v[i] +=3;
    }
  }
  for (int i = 1; i <= 7; i++) {
    if (v[i] && v[i+1] && v[i+2]) {
      v[i]--; v[i+1]--; v[i+2]--;
      if (check(v))
        return true;
      v[i]++; v[i+1]++; v[i+2]++;
    }
  }
  return false;
}

void Puzzle(vi& v)
{
  vi res;
  for (int i = 1; i < 10; i++) {
    vi u(10, 0);
    u[i]++;
    for (auto ii : v) {
      u[ii]++;
    }
    if (!valid(u))
      continue;
    for (int j = 1; j < 10; j++) {
      if (u[j] < 2)
        continue;
      u[j] -= 2;
      if (check(u)) {
        res.pb(i);
        break;
      }
      u[j] += 2;
    }
  }
  if (sz(res)) {
    rep (i, sz(res)) {
      cout << (i?" ":"") << res[i];
    }
    cout << endl;
  } else {
    cout << 0 << endl;
  }
}

vi s2vi(string& s)
{
  vi v;
  for (auto& c : s) {
    v.pb(c - '0');
  }
  return v;
}

int main(int argc, char **argv)
{
  string s;
  while (getline(cin, s)) {
    vi v = s2vi(s);
    Puzzle(v);
  }
  return 0;
}