#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); V t; for (int i = 0; i < 9; ++i) { t.push_back(string(3, '1' + i)); if (i < 7) { string x; x += '1' + i; x += '1' + i + 1; x += '1' + i + 2; t.push_back(x); } } V s; for (int i = 0; i < 1 << 16; ++i) { for (int j = 0; j < 9; ++j) { string x(2, '1' + j); x += t[i & 15]; x += t[i >> 4 & 15]; x += t[i >> 8 & 15]; x += t[i >> 12 & 15]; sort(begin(x), end(x)); s.push_back(x); } } V<> p{0, 0, 1, 1, 1, 1, 1, 1, 1}; do { string x; for (int i = 0; i < 9; ++i) if (p[i]) { x += string(2, '1' + i); } sort(begin(x), end(x)); s.push_back(x); } while (next_permutation(begin(p), end(p))); for (auto&& e : s) { bool ok = true; for (int i = 0; i < 9; ++i) if (count(begin(e), end(e), '1' + i) > 4) { ok = false; break; } if (!ok) e = ""; } sort(begin(s), end(s)); s.erase(unique(begin(s), end(s)), end(s)); string str; cin >> str; for (int i = 0; i < 9; ++i) { auto x = str; x += '1' + i; sort(begin(x), end(x)); if (!binary_search(begin(s), end(s), x)) continue; cout << i + 1 << '\n'; } }