#include <bits/stdc++.h>

using namespace std;

bool solve(int cpy[]) {
    int c[10] = {};
    bool flag = false;

    for (int i = 1; i <= 9; i++)
        c[i] = cpy[i];

    for (int i = 0; i < 10; i++) {
        for (int j = 1; j <= 9; j++) {
            if (!c[j]) continue;
            if (c[j] == 3) {
                bool only_three = true;
                for (int k = 1; k <= 9; k++)
                    if (c[k] != 0 && c[k] != 3) only_three = false;

                if (only_three) return true;

                c[j] = 0;
                break;
            } else {
                if (j + 2 <= 9 && c[j + 1] >= 1 && c[j + 2] >= 1)
                    c[j]--, c[j + 1]--, c[j + 2]--;
                else if (c[j] == 4)
                    c[j] -= 3;
                else
                    return false;
                break;
            }
        }
    }

    for (int i = 1; i <= 9; i++)
        if (c[i]) return false;

    return true;
}

int main() {
    string s;

    while (cin >> s) {
        int cnt[10] = {};
        for (int i = 0; i < s.size(); i++)
            cnt[s[i] - '0']++;
        
        bool flag = false;
        for (int i = 1; i <= 9; i++) {
            int cpy[10];

            for (int j = 0; j < 10; j++)
                cpy[j] = cnt[j];
            cpy[i]++;
            if (cpy[i] > 4) continue;

            for (int j = 1; j <= 9; j++) {
                if (cpy[j] < 2) continue;
                
                cpy[j] -= 2;
                if (solve(cpy)) {
                    if (flag) cout << " ";
                    cout << i;
                    flag = true;
                    break;
                }
                cpy[j] += 2;
            }
        }
        if (!flag) cout << "0";
        cout << endl;
    }

    return 0;
}
