#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>

using namespace std;

int hailist[14];
int shaicount[10];
int haicount[10];
set<int> ans;
bool dfs(int i);
void solve(int *hailist);

int main()
{
	while(1){
		int eof;
		fill(hailist,hailist+13,0);
		for(int i=0;i<13;i++){
			char temp;
			eof=scanf(" %c",&temp);
			if(eof==EOF)break;
			hailist[i]=(int)temp-'0'-1;
		}
		if(eof==EOF)break;
		ans.clear();
		solve(hailist);
		if(ans.empty())cout<<0<<"\n";
		else{
			set<int>::iterator it = ans.begin();
			for(int i=0;i<ans.size()-1;i++){cout<<*it<<" ";it++;}
			cout<<*it<<"\n";
		}
	}
	return 0;
}

void solve(int *hailist){
	for(int i=0;i<10;i++) shaicount[i]=0;
	shaicount[9]=1;//[vI¹Ì½ßÉ
	for(int i=0;i<13;i++) shaicount[hailist[i]]++;//²ÆÉvÌðJEg
	for(int i=0;i<9;i++){
		if(shaicount[i]==4)continue;
		for(int j=0;j<10;j++)haicount[j]=shaicount[j];
		haicount[i]++;//vðêÂ«·

		for(int j=0;j<9;j++){
			if(haicount[j]>=2){
				haicount[j]-=2;
				//for(int i=0;i<9;i++)cout<<haicount[i];
				//cout<<"\n";
				if(dfs(0)) {ans.insert(i+1);break;}
				haicount[j]+=2;
			}
		}
	}
	return;
}
bool dfs(int i){
	while(!haicount[i])i++;
	if(i==9)return true;
	if(haicount[i]>=3){
		haicount[i]-=3;//Ï»·éOÌóÔðÛ¶µÈ¢Æg¦È¢H
		if(dfs(i))return true;
		haicount[i]+=3;
	}
	if(i>=7)return false;
	if(haicount[i]&&haicount[i+1]&&haicount[i+2]){
		haicount[i]--;haicount[i+1]--;haicount[i+2]--;
		if(dfs(i))return true;
		haicount[i]++;haicount[i+1]++;haicount[i+2]++;
	}
	return false;
}