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

// vi[i-1]?????°???i??????????????°
bool isCompleted(vector<int> vi) {
    //?????????2??? && ??????????????°??????????????§true??????????????????
    int zero = std::count(vi.begin(), vi.end(), 0);
    if(zero == 8) return true;

    //??????
    for(int i=1; i<=9; ++i) {
        if(vi[i-1] >= 3) {
            vi[i-1] -= 3;
            if(isCompleted(vi)) return true;
            vi[i-1] += 3;
        }
    }
    //??????
    for(int i=1; i<=7; ++i) {
        if(vi[i-1] >= 1 && vi[i] >= 1 && vi[i+1] >= 1) {
            --vi[i-1]; --vi[i]; --vi[i+1];
            if(isCompleted(vi)) return true;
            ++vi[i-1]; ++vi[i]; ++vi[i+1];
        }
    }
    return false;
}

int main(int argc, char** argv) {
    vector<int> vi; // vi[i-1]?????°???i??????????????°
    string str;
    while(cin >> str) {
        vi.assign(9, 0);
        for(unsigned int i=0; i<str.size(); ++i) {
            ++vi[str[i]-'0'-1];
        }
        bool isFound = false;
        for(int i=1; i<=9; ++i) {
            if(vi[i-1] == 4) continue;
            ++vi[i-1];
            if(isCompleted(vi)) {
                if(isFound) cout << " ";
                isFound = true;
                cout << i;
            }
            --vi[i-1];
        }
        if(!isFound) cout << "0";
        cout << endl;
    }
    return 0;
}