#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <bitset>
#include <memory.h>

using namespace std;



int check(int num_counter[], int now, int flag);


int main() {
    char c_num[13];
    int i_num[14];
    while(cin>>c_num[0]){
        for(int i=1; i<13; i++)cin>>c_num[i];
        
        int ans_flag=0;
        for(int i=1; i<=9; i++){
            for(int j=0; j<13; j++)i_num[j]=c_num[j]-'0';
            i_num[13]=i;
            
            int num_counter[12]={0};
            for(int j=0; j<14; j++)num_counter[i_num[j]]++;
            
            int now=1;
            int flag=0;
            int ans = 0;
            int pass= 0;
        
            for(int j=1; j<=9; j++){
                if(num_counter[j]>=5)pass++;
            }
            

            if(pass==0)ans = check(num_counter, now, flag);
            if(ans==1){
                cout<<i<<" ";
                ans_flag++;
            }
            
    
        }
        if(ans_flag==0)cout<<0<<" ";
        cout<<endl;
        
        
        
    
    }
    return 0;
}

int check(int num_counter[], int now, int flag){
    if(now==10){
        return 1;
    }
    int num_counter_temp[12];
    if(num_counter[now]==5){
        return 0;
    }
    if(num_counter[now]>0&&num_counter[now+1]>0&&num_counter[now+2]>0){
        memcpy(num_counter_temp, num_counter, sizeof(int)*12);
        num_counter_temp[now]--;
        num_counter_temp[now+1]--;
        num_counter_temp[now+2]--;
        if(check(num_counter_temp, now, flag)==1)return 1;
    }
    if(num_counter[now]>=3){
        memcpy(num_counter_temp, num_counter, sizeof(int)*12);
        num_counter_temp[now]-=3;
        if(check(num_counter_temp, now, flag)==1)return 1;
    }
    if(num_counter[now]>=2&&flag==0){
        memcpy(num_counter_temp, num_counter, sizeof(int)*12);
        num_counter_temp[now]-=2;
        if(check(num_counter_temp, now, flag+1)==1)return 1;
    }
    if(num_counter[now]==0){
        memcpy(num_counter_temp, num_counter, sizeof(int)*12);
        if(check(num_counter_temp, now+1, flag)==1)return 1;
    }
    
    
    return 0;
    
    
}