#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	string input;
	vector<int> in(11),a;
	vector<int> ans;
	while(cin>>input){
		ans.clear();
		fill(in.begin(),in.end(),0);
		for(int i=0;i<13;i++){
			++in[input[i]-'1'];
		}
		for(int i=0;i<9;i++){
			if(in[i]==4)continue;
			for(int j=0;j<9;j++){//枕
				a=in;
				++a[i];
				if(a[j]<2)continue;
				a[j] -= 2;
				for(int k=0;k<9;k++){
					int num;
					a[k] %= 3;
					num = min(min(a[k],a[k+1]),a[k+2]);
					if(a[k]==num){
						a[k] -= num;
						a[k+1] -= num;
						a[k+2] -= num;
					}
					else break;
				}
				if(count(a.begin(),a.end(),0)==11){
					ans.push_back(i+1);
					break;
				}
			}
		}
		if(ans.empty())ans.push_back(0);
		cout<<ans[0];
		for(int i=1;i<ans.size();i++){
			cout<<' '<<ans[i];
		}
		cout<<endl;
	}
	return 0;
}