#include //#include using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); setst; rep2(i, 1, 10)rep2(j, i + 1, 10)rep2(k, j + 1, 10)rep2(l, k + 1, 10)rep2(m, l + 1, 10)rep2(n, m + 1, 10)rep2(o, n + 1, 10) { string str; rep(_, 2)str += i + '0'; rep(_, 2)str += j + '0'; rep(_, 2)str += k + '0'; rep(_, 2)str += l + '0'; rep(_, 2)str += m + '0'; rep(_, 2)str += n + '0'; rep(_, 2)str += o + '0'; st.insert(str); } rep2(i, 1, 10)rep2(j, 1, 10)rep2(k, 1, 10)rep2(l, 1, 10)rep2(m, 1, 10) { rep(t0, 2)rep(t1, 2)rep(t2, 2)rep(t3, 2) { vectorcnt(12); string str; rep(_, 2) { str += i + '0'; cnt[i]++; } auto f = [&](int x, int type)->void { rep(_, 3) { str += x + _ * type + '0'; cnt[x + _ * type]++; } }; f(j, t0), f(k, t1), f(l, t2), f(m, t3); bool chk = true; rep(i, 12) { if (cnt[i] > 4)chk = false; if ((i >= 10) && (cnt[i]))chk = false; } if (!chk)break; sort(all(str)); st.insert(str); } } string s; cin >> s; rep2(i, 1, 10) { auto cs = s; cs += i + '0'; sort(all(cs)); if (st.count(cs)) cout << i << endl; } return 0; }