#include <iostream>
#include <vector>

using namespace std;

bool dfs(int c[10])
{
    bool ret = false;
    int sum = 0;

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

    for (int i = 1; i <= 7; i++) {
        if (c[i] >= 1 && c[i + 1] >= 1 && c[i + 2] >= 1) {
            c[i]--, c[i + 1]--, c[i + 2]--;
            ret = dfs(c);
            c[i]++, c[i + 1]++, c[i + 2]++;
        }
    }
    for (int i = 1; i <= 9; i++)
        if (c[i] >= 3) {
            c[i] -= 3;
            ret = dfs(c);
            c[i] += 3;
        }
    return ret;
}


int main()
{
    string inp;

    while (cin >> inp) {
        bool flag = false;
        vector<int> ans;

        for (int i = 1; i <= 9; i++) {
            int cnt[10];

            // Initialization
            for (int j = 1; j <= 9; j++)
                cnt[j] = 0;
            for (int j = 0; j < inp.size(); j++) 
                cnt[inp[j] - '0']++;
            cnt[i]++;

            for (int j = 1; j <= 9; j++) {
                if (cnt[j] >= 2 && cnt[j] <= 4) {
                    cnt[j] -= 2;
                    if (dfs(cnt)) {
                        flag = true;
                        ans.push_back(i);
                        break;
                    }
                    cnt[j] += 2;
                }
            }
        }
        // Output
        if (flag) {
            for (int i = 0; i < ans.size() - 1; i++)
                cout << ans[i] << " ";
            cout << ans[ans.size() - 1] << endl;
        }
        else
            cout << 0 << endl;
    }

    return 0;
}