#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

bool solve(vector<int> nums, int conb)
{
	//if(conb==4) return true;
	int now=0;
	while(nums[now]==0&&now<9) now++;

	if(now==9) return true;
	if(nums[now]>2) //刻子にする場合
	{
		nums[now]-=3;
		if(solve(nums,conb+1)) return true;
		nums[now]+=3;
	}

	if(now<7&&nums[now]&&nums[now+1]&&nums[now+2]) //順子にする場合
	{
		nums[now]-=1;	
		nums[now+1]-=1;	
		nums[now+2]-=1;	
		if(solve(nums,conb+1)) return true;
		nums[now]+=1;	
		nums[now+1]+=1;	
		nums[now+2]+=1;	
	}
	
	return false;

}


int main()
{
	string in;
	while (cin>>in) 
	{
		bool ans[9];
		fill(ans,ans+9,false);
		vector<int> nums(9,0);
		for(int i = 0; i < 13; ++i)
		{
			nums[in[i]-'1']++;
		}
		/*for(int i = 0; i < 9; ++i)
		{
			cout<<i+1<<"="<<nums[i]<<endl;
		}*/
		vector<int> cp=nums;
		for(int i = 1; i < 10; ++i)
		{
			if(cp[i-1]==4) continue;
			cp[i-1]++;
			for(int j = 1; j < 10; ++j)
			{
				if(cp[j-1]<1) continue;
				cp[j-1]-=2;
				if(solve(cp,0)) ans[i-1]=true;
				cp[j-1]+=2;
			}
			cp[i-1]--;	
		}
	
		int cnt=0;
		for(int i = 0; i < 9; ++i)
		{
			if(ans[i])
			{
				if(cnt!=0) cout<<" "<<i+1;
				else cout<<i+1;
				cnt++;
			}
		}
		if(cnt==0) cout<<0;
		cout<<endl;
	}
  return 0;
}