#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define itrep(it, a) for(it = (a).begin(); it != (a).end(); it++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

bool anko(map<int, int> mii){
    rep(i,10){
        if(mii[i] > 0 && mii[i + 1] > 0 && mii[i + 2] > 0){
            mii[i]--; mii[i + 1]--; mii[i + 2]--;
            i--;
            continue;
        }
    }
    range(i,1,10) mii[i]%=3;
    range(i,1,10) if(mii[i] != 0) return false;
    return true;
}

bool jun(map<int, int> mii){
    range(i,1,10) mii[i]%=3;
    rep(i,10){
        if(mii[i] > 0 && mii[i + 1] > 0 && mii[i + 2] > 0){
            mii[i]--; mii[i + 1]--; mii[i + 2]--;
            i--;
            continue;
        }
    }
    range(i,1,10) if(mii[i] != 0) return false;
    return true;
}

bool solve(map<int, int> mii, int a){
    mii[a]-=2;
    if(anko(mii) || jun(mii)) return true;
    else return false;
}

bool check(map<int, int> mii, int a){
    mii[a]++;
    range(i,1,10){
        if(mii[i] >= 2){ //???????????????????????????????????¨??¢?´¢
            if(solve(mii, i)){
                return true;
            }
        }
    }
    return false;
}

int main(){
    string str;
    while(cin >> str){
        bool c = false;
        map<int ,int> mii;
        rep(i, str.size()) mii[str[i] - '0']++;
        range(i,1,10){
            if(mii[i] == 4) continue; //????????°??????????????\???????????????
            if(check(mii, i)){
                if(c) cout << ' ';
                cout << i;
                c = true;
            }
        }
        if(not c) cout << 0;
        cout << endl;
    }
}