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

int count_melds(int* cnt)
{
    int i;
    int maxi = 0;

    for (i = 1; i < 10; ++i){
        if (3 <= cnt[i]){
            cnt[i] -= 3;
            maxi = max(maxi, 1 + count_melds(cnt));
            cnt[i] += 3;
        }
        if (i <= 7 && cnt[i] && cnt[i + 1] && cnt[i + 2]){
            --cnt[i];
            --cnt[i + 1];
            --cnt[i + 2];
            maxi = max(maxi, 1 + count_melds(cnt));
            ++cnt[i];
            ++cnt[i + 1];
            ++cnt[i + 2];
        }
    }

    return maxi;
}

bool has_hand(int* cnt)
{
    for (int i = 1; i < 10; ++i){
        if (2 <= cnt[i]){
            cnt[i] -= 2;
            int melds = count_melds(cnt);
            cnt[i] += 2;
            if (melds == 4) return true;
        }
    }

    return false;
}

int main(void)
{
    int tile;

    while (~scanf("%1d", &tile)){
        int cnt[10] = {0};
        vector<int> waiting;

        ++cnt[tile];
        for (int i = 1; i < 13; ++i){
            scanf("%1d", &tile);
            ++cnt[tile];
        }

        for (int i = 1; i < 10; ++i){
            if (cnt[i] == 4) continue;

            ++cnt[i];
            if (has_hand(cnt)){
                waiting.push_back(i);
            }
            --cnt[i];
        }

        if (waiting.empty()){
            puts("0");
        }
        else {
            printf("%d", waiting[0]);
            for (int i = 1; i < waiting.size(); ++i) printf(" %d", waiting[i]);
            puts("");
        }
    }

    return 0;
}