#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

string s;
int cnt[10];

bool dfs(int* c, int num) {
  if (num == 4) return true;
  for (int i = 1; i < 10; i++) {
    if (c[i] >= 3) {
      c[i] -= 3;
      if (dfs(c, num + 1)) return true;
      c[i] += 3;
    }
    if (i + 2 < 10 && c[i] && c[i + 1] && c[i + 2]) {
      c[i]--, c[i + 1]--, c[i + 2]--;
      if (dfs(c, num + 1)) return true;
      c[i]++, c[i + 1]++, c[i + 2]++;
    }
  }
  return false;
}

bool check(int d) {
  int c[10];
  memcpy(c, cnt, sizeof(cnt));
  if (++c[d] > 4) return false;
  bool ok = false;
  for (int i = 1; !ok && i < 10; i++) {
    if (c[i] >= 2) {
      c[i] -= 2;
      ok |= dfs(c, 0);
      c[i] += 2;
    }
  }
  return ok;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> s) {
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < 13; i++) {
      cnt[s[i] - '0']++;
    }
    vector<int> ans;
    for (int i = 1; i < 10; i++) {
      if (check(i)) ans.emplace_back(i); 
    }
    if (ans.empty()) {
      cout << "0" << endl;
      continue;
    }
    for (int i = 0; i < (int)ans.size(); i++) {
      cout << ans[i] << " \n"[i + 1 == (int)ans.size()];
    }
  }

  return 0;
}
