#include <iostream>
#include <string>

using namespace std;

int ds[10];

bool check3(int c = 4) {
  if (!c) return true;
  for (int d = 1; d <= 9; d++) {
    bool result = false;
    if (ds[d] >= 3) {
      ds[d] -= 3;
      result = check3(c-1);
      ds[d] += 3;
      if (result) return true;
    }
    if (d <= 7 && ds[d] && ds[d+1] && ds[d+2]) {
      ds[d]--; ds[d+1]--; ds[d+2]--;
      result = check3(c-1);
      ds[d]++; ds[d+1]++; ds[d+2]++;
      if (result) return true;
    }
  }
  return false;
}

bool check() {
  for (int d = 1; d <= 9; d++) {
    if (ds[d] >= 2) {
      bool result = false;
      ds[d] -= 2;
      result = check3();
      ds[d] += 2;
      if (result) return true;
    }
  }
  return false;
}

int main() {
  string s;
  while (getline(cin, s)) {
    bool rs[10];
    int maxd = 0;
    for (int d = 1; d <= 9; d++) {
      rs[d] = false;
      ds[d] = 0;
    }
    for (int i = 0; i < 13; i++)
      ds[s[i]-'0']++;
    for (int d = 1; d <= 9; d++) {
      if (ds[d] >= 4) continue;
      ds[d]++;
      if (check()) {
        rs[d] = true;
        maxd = d;
      }
      ds[d]--;
    }
    if (maxd) {
      for (int d = 1; d <= 9; d++)
        if (rs[d])
          if (d == maxd)
            cout << d << endl;
          else
            cout << d << " ";
    } else
      cout << "0" << endl;
  }
  return 0;
}