#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define Ma_PI 3.141592653589793 #define eps 0.00000000000000000000000001 #define LONG_INF 10000000000000000LL #define GOLD 1.61803398874989484820458 #define MAX_MOD 1000000007 #define MOD 998244353 #define REP(i,n) for(long long i = 0;i < n;++i) long long inv(long long now) { long long ans = 1; long long te = MAX_MOD - 2LL; while (te != 0) { if (te % 2 == 1) { ans *= now; ans %= MAX_MOD; } te /= 2; now *= now; now %= MAX_MOD; } return ans; } int cnt[20] = {}; int solve(long long step) { int cnter = 0; int type = 0; REP(i, 9) { cnter += cnt[i + 1]; if (cnt[i + 1] >= 1) { type++; } } if (cnter == 2&&type == 1) { return 1; } for (int i = step; i < 20; ++i) { if (i < 9) { if (cnt[i + 1] >= 3) { cnt[i + 1] -= 3; int hoge = solve(i); cnt[i + 1] += 3; if (hoge == 1) { return 1; } } } else { //narabi int tea = i - 9; if (cnt[tea + 1] >= 1 && cnt[tea + 2] >= 1 && cnt[tea + 3] >= 1) { cnt[tea + 1]--; cnt[tea + 2]--; cnt[tea + 3]--; int hoge = solve(i); cnt[tea + 1]++; cnt[tea + 2]++; cnt[tea + 3]++; if (hoge == 1) { return 1; } } } } return 0; } int main(){ string s; cin >> s; REP(i, s.length()) { cnt[s[i] - '0']++; } for (int i = 1; i < 10; ++i) { if (cnt[i] == 4) continue; cnt[i]++; if (solve(0) == 1) { cout << i << endl; } else { int hoge = 0; for (int q = 1; q <= 10; ++q) { hoge += cnt[q] % 2; if (cnt[q] == 4) hoge++; } if (hoge == 0) { cout << i << endl; } } cnt[i]--; } return 0; }