#include <iostream>
#include <iterator>
#include <string>
#include <vector>
using namespace std;
bool solve(vector<int>& c, int ok) {
  if (ok >= 4) return true;
  bool p = false;
  for (int i = 1; i <= 9; i++)
    if (c[i] >= 3) {
      c[i] -= 3;
      p = p || solve(c, ok + 1);
      c[i] += 3;
    }
  for (int i = 1; i <= 7; i++)
    if (c[i] >= 1 && c[i + 1] >= 1 && c[i + 2] >= 1) {
      c[i]--;
      c[i + 1]--;
      c[i + 2]--;
      p = p || solve(c, ok + 1);
      c[i]++;
      c[i + 1]++;
      c[i + 2]++;
    }
  return p;
}
int main() {
  string line;
  while (getline(cin, line)) {
    vector<int> c(10, 0);
    for (auto& e : line)
      c[e - '0']++;
    vector<int> ans;
    for (int add = 1; add <= 9; add++) {
      c[add]++;
      vector<int> t;
      bool p = false;
      for (int i = 1; i <= 9; i++) {
        if (c[i] > 4) goto NEXT;
        if (c[i] >= 2) t.push_back(i);
      }
      for (auto& e : t) {
        c[e] -= 2;
        p = p || solve(c, 0);
        c[e] += 2;
      }
      if (p) ans.push_back(add);
      NEXT:
      c[add]--;
    }
    if (!ans.empty()) {
      for (int i = 0; i < (int) ans.size() - 1; i++)
        cout << ans[i] << ' ';
      cout << *ans.rbegin() << endl;
    }
    else cout << 0 << endl;
  }
}