#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iterator>
#include<vector>
using namespace std;
#define int long long
bool ch(int n, vector<int> &pat){
	if(n==0){
		int flag = false;
		for(int i=0;i<9;i++){
			if(pat[i]==2) flag = true;
		}
		return flag;
	}
	for(int i=0;i<7;i++){
		if(pat[i]>0 && pat[i+1]>0 && pat[i+2]>0){
			vector<int> pat2;
			copy(pat.begin(), pat.end(), back_inserter(pat2));
			pat2[i]--;
			pat2[i+1]--;
			pat2[i+2]--;
			if( ch(n-1, pat2) ) return true;
		}
	}
	for(int i=0;i<9;i++){
		if(pat[i]>=3){
			vector<int> pat2;
			copy(pat.begin(), pat.end(), back_inserter(pat2));
			pat2[i]-=3;
			if( ch(n-1, pat2) ) return true;
		}
	}
	return false;
}
signed main(){
	char buf[128];
	while( scanf("%s", buf) != EOF ){
		vector<int> pat(9,0);
		for(int i=0;i<13;i++){
			pat[buf[i]-'1']++;
		}
		int count = 0;
		for(int i=0;i<9;i++){
			if(pat[i]<4){
				vector<int> pat2;
				copy(pat.begin(), pat.end(), back_inserter(pat2));
				pat2[i]++;
				if(ch(4,pat2)){
					if(count > 0) cout << " ";
					cout << i+1;
					count++;
				}
			}
		}
		if(count==0) cout << 0 ;
		cout << endl;
	}
	return 0;
}