#include <bits/stdc++.h>
using namespace std;

bool mentsu(vector<int>& cnt) {
    for(int i = 0; i + 2 < 9; ++i) {
        int r = cnt[i] % 3;
        if(cnt[i + 1] >= r && cnt[i + 2] >= r) {
            cnt[i + 1] -= r, cnt[i + 2] -= r;
        } else {
            return false;
        }
    }
    return cnt[7] % 3 == 0 && cnt[8] % 3 == 0;
}

bool check(vector<int> const& cnt) {
    for(int i = 0; i < 9; ++i) {
        if(cnt[i] < 2) continue;
        auto tmp = cnt;
        tmp[i] -= 2;
        if(mentsu(tmp)) {
            return true;
        }
    }
    return false;
}

int main() {
    string hand;
    while(cin >> hand) {
        vector<int> cnt(9), ans;
        for(auto c : hand) {
            cnt[c - '0' - 1]++;
        }

        for(int i = 1; i <= 9; ++i) {
            if(cnt[i - 1] >= 4) {
                continue;
            }
            cnt[i - 1]++;
            if(check(cnt)) ans.push_back(i);
            cnt[i - 1]--;
        }

        if(ans.empty()) {
            ans.push_back(0);
        }
        for(int i = 0; i < (int)ans.size(); ++i) {
            cout << ans[i] << " \n"[i + 1 == (int)ans.size()];
        }
    }
}
