#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;
const int N = 10;

bool dfs(int cards[N], int now, int cnt3, int cnt2){
    if(cnt3 == 4 && cnt2 == 1) return true;
    else if(now >= N) return false;
    else{
        bool ret = false;

        if(cnt3 < 4){
            if(cards[now] >= 3){
                REP(i, 3) cards[now]--;
                ret = max(ret, dfs(cards, now, cnt3 + 1, cnt2));
                REP(i, 3) cards[now]++;
            }
            if(now <= 7 && cards[now] && cards[now + 1] && cards[now+ 2]){
                REP(i, 3) cards[now + i]--;
                ret = max(ret, dfs(cards, now, cnt3 + 1, cnt2));
                REP(i, 3) cards[now + i]++;
            }
        }
        if(!cnt2 && cards[now] >= 2){
            REP(i, 2) cards[now]--;
            ret = max(ret, dfs(cards, now, cnt3, cnt2 + 1));
            REP(i, 2) cards[now]++;
        }
        ret = max(ret, dfs(cards, now + 1, cnt3, cnt2));
        return ret;
    }
}


int main(){
    string str;
    while(cin >>str){
        int cards[N] = {0};
        REP(i, str.size()) cards[str[i] - '0']++;

        vector<int> ans;
        FOR(i, 1, N){
            if(cards[i] > 3) continue;
            cards[i]++;
            if(dfs(cards, 1, 0, 0)) ans.push_back(i);
            cards[i]--;
        }

        if(ans.size() == 0) cout <<0 <<endl;
        else{
            sort(ans.begin(), ans.end());
            REP(i, ans.size()){
                if(i == 0) cout <<ans[i];
                else cout <<" " <<ans[i];
            }
            cout <<endl;
        }
    }
    return 0;
}