#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int func(int v[9], int n){
	
	int k, index, vv[9];
	
	index = 0;
	
	for(int i=0; i<9; i++){
		vv[i] = v[i];
	}
	
	for(int i=0; i<5; i++){
		k = 0;
		if(i != n){
			while(vv[index] == 0) index++;
			if(vv[index] >= 3) vv[index] -= 3;
			else if(vv[index + 1] != 0 && vv[index + 2] != 0){
				vv[index]--;
				vv[index + 1]--;
				vv[index + 2]--;
			}
			else return 1;
		}
		else{
			while(vv[index] == 0) index++;
			if(vv[index] >= 2) vv[index] -= 2;
			else return 1;
		}
	}
	
	return 0;
	
}

int main(){

	int cnt;
	int v[9] = {};
	string str; 

	while(cin >> str){
		cnt = 0;
	
		fill(v, v+9, 0);
		for(int i=0; i<13; i++){
			v[str[i] - '0' - 1]++;
		}

		for(int i=0; i<9; i++){
			v[i]++;
			if(v[i] < 5){
			
				for(int j=0; j<5; j++){
					if(func(v, j) == 0){
						if(cnt != 0) cout << " " << i + 1;
						else cout << i + 1;
						cnt++;
						break;
					}
				}
		
			}
			v[i]--;
		}
		if(cnt == 0) cout << 0;
		cout << endl;
	}

	return 0;

}