#include <iostream>
#include <cstring>

using namespace std;

int num[10];

bool isEnd() {
    int zero = 0, two = 0;
    for (int i=1; i<=9; ++i) {
        if (num[i] == 0) zero ++;
        if (num[i] == 2) two ++;
    }
    return zero == 8 && two == 1;
}

bool dfs() {
    bool ok;
    if (isEnd()) return true;
    for (int i=1; i<=7; ++i) {
        if (num[i] && num[i+1] && num[i+2]) {
            num[i] --; num[i+1] --; num[i+2] --;
            ok = dfs();
            num[i] ++; num[i+1] ++; num[i+2] ++;
            if (ok) return true;
        }
    }
    for (int i=1; i<=9; ++i) {
        if (3 <= num[i]) {
            num[i] -= 3;
            ok = dfs();
            num[i] += 3;
            if (ok) return true;
        }
    }
    return false;
}

int main() {
    string s;
    while (cin >> s) {
        memset(num, 0, sizeof num);
        for (int i=0; i<13; ++i) num[s[i] - '0'] ++;
        bool fst = true;
        bool ok;
        for (int i=1; i<=9; ++i) {
            if (4 <= num[i]) continue;
            num[i] ++;
            ok = dfs();
            num[i] --;
            if (ok) {
                cout << (fst ? "" : " ") << i;
                fst = false;
            }
        }
        if (fst) {
            cout << 0 << endl;
        } else {
            cout << endl;
        }
    }
    return 0;
}