#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

bool hasMoreThanFive(vector<int> v) {
    // already sorted
    int cnt = 1;
    int maxcnt = 1;
    REP(i,13) {
        if (v[i] == v[i+1]) cnt++;
        else {
            maxcnt = max(maxcnt, cnt);
            cnt = 1;
        }
    }
    maxcnt = max(maxcnt, cnt);
    return maxcnt >= 5;
}

bool hasPairs(vector<int> v, int a) {
    return upper_bound(v.begin(), v.end(), a) - lower_bound(v.begin(), v.end(), a) >= 2;
}

int hasTwo(vector<int> v) {
    int cnt = 1;
    REP(i,v.size()-1) {
        if (v[i] == v[i+1]) cnt++;
        else {
            if (cnt == 2) return v[i];
            else cnt = 1;
        }
    }
    if (cnt == 2) return v.back();
    return -1;
}

int hasOne(vector<int> v) {
    int cnt = 1;
    REP(i,v.size()-1) {
        if (v[i] == v[i+1]) cnt++;
        else {
            if (cnt == 1) return v[i];
            else cnt = 1;
        }
    }
    if (cnt == 1) return v.back();
    return -1;
}

bool hasOneBigger(vector<int> v, int a) {
    return find(v.begin(),v.end(),a+1) != v.end();
}

bool checkSets(vector<int> v) {
    // at first, size is 12
    int n;
    if ((n = hasOne(v)) != -1 || (n = hasTwo(v)) != -1) {
        vector<int> w(v);
        if (hasOneBigger(v, n) && hasOneBigger(v, n+1)) {
            w.erase(find(w.begin(),w.end(),n));
            w.erase(find(w.begin(),w.end(),n+1));
            w.erase(find(w.begin(),w.end(),n+2));
            if (w.size() == 0 || checkSets(w)) return true;
        }
        w.clear();
        copy(v.begin(),v.end(),back_inserter(w));
        if (hasOneBigger(v, n-2) && hasOneBigger(v, n)) {
            w.erase(find(w.begin(),w.end(),n-1));
            w.erase(find(w.begin(),w.end(),n));
            w.erase(find(w.begin(),w.end(),n+1));
            if (v.size() == 0 || checkSets(w)) return true;
        }
        w.clear();
        copy(v.begin(),v.end(),back_inserter(w));
        if (hasOneBigger(v, n-3) && hasOneBigger(v, n-2)) {
            w.erase(find(w.begin(),w.end(),n-2));
            w.erase(find(w.begin(),w.end(),n-1));
            w.erase(find(w.begin(),w.end(),n));
            if (v.size() == 0 || checkSets(w)) return true;
        }
        return false;
    }
    return true;
}

bool whenTwoPairIs(int a, vector<int> v) {
    v.erase(find(v.begin(),v.end(),a));
    v.erase(find(v.begin(),v.end(),a));
    // now there are 12 integers. divide them in 4 sets (369600 choises) and examine
    return checkSets(v);
}

bool win(vector<int> v, int a) {
    v.push_back(a);
    sort(v.begin(),v.end());
    if (hasMoreThanFive(v)) return false;
    vector<int> pairs;
    FOR(i,1,10) if (hasPairs(v,i)) pairs.push_back(i);
    REP(i,pairs.size()) {
        if (whenTwoPairIs(pairs[i],v)) return true;
    }
    return false;
}

int main() {
    string s;
    while (cin >> s) {
        vector<int> v;
        REP(i,13) {
            v.push_back(s[i]-'0');
        }
        vector<int> solution;
        FOR(i,1,10) {
            if (win(v,i)) solution.push_back(i);
        }
        if (solution.size() == 0) cout << 0 << endl;
        else {
            REP(i,solution.size()-1) cout << solution[i] << " ";
            cout << solution.back() << endl;
        }
    }
    return 0;
}