#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

bool is_ok(vector<int> seq, int dnum, int tnum) {
  int target = -1;
  for (int i = 0; i < 9; ++i) {
    if (0 < seq[i]) {
      target = i;
      break;
    }
  }
  int maxv = *max_element(seq.begin(), seq.end());
  int minv = *min_element(seq.begin(), seq.end());

  if ((5 <= maxv) || (minv < 0))
    return false;

  if ((dnum == 0) && (tnum == 0))
    return true;

  vector<int> copy = seq;
  if ((dnum != 0)) {
    copy[target] -= 2;
    if (is_ok(copy, dnum - 1, tnum))
      return true;
  }

  if ((tnum != 0) && (target < 7)) {
    copy = seq;
    copy[target] -= 1;
    copy[target + 1] -= 1;
    copy[target + 2] -= 1;
    if (is_ok(copy, dnum, tnum - 1))
      return true;
  }

  if ((tnum != 0)) {
    copy = seq;
    copy[target] -= 3;
    if (is_ok(copy, dnum, tnum - 1))
      return true;
  }

  return false;
}

int main() {
  string tmp;

  while (cin >> tmp) {
    vector<int> seq(9);
    for (int i = 0; i < 13; ++i) {
      int idx = tmp[i] - '1';
      ++seq[idx];
    }

    vector<int> res;
    for (int i = 0; i < 9; ++i) {
      vector<int> seq_copy = seq;
      seq_copy[i] += 1;
      if (is_ok(seq_copy, 1, 4))
        res.push_back(i + 1);
    }

    if (res.empty()) {
      cout << 0 << endl;
    } else {
      for (auto &v : res)
      {
        if (v == res[0])
          cout << v;
        else
          cout << " " << v;
      }
      cout << endl;
    }
  }

  return EXIT_SUCCESS;
}
