#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>

using namespace std;

char c;

void solve(map<int,int> *num, map<int,int> *ans,int a)
{
	int n=0;
	for(int i=1;i<=9;i++)
	{
		n+=(*num)[i];
	}
	if(n==0)
	{
		(*ans)[a]++;
		return;
	}
	for(int i=1;i<=9;i++)
	{
		if((*num)[i]>=3)
		{
			(*num)[i]-=3;
			solve(num,ans,a);
			(*num)[i]+=3;
		}
	}
	for(int i=3;i<=9;i++)
	{
		if((*num)[i]&&(*num)[i-1]&&(*num)[i-2])
		{
			(*num)[i]--;
			(*num)[i-1]--;
			(*num)[i-2]--;
			solve(num,ans,a);
			(*num)[i]++;
			(*num)[i-1]++;
			(*num)[i-2]++;
		}
	}
}

int main(void)
{
	string s;
	while(getline(cin,s))
	{
		map<int,int> ans;
		map<int,int> num;
		for(int i=0;i<s.size();i++)
		{
			num[s[i]-'0']++;
		}
		for(int i=1;i<=9;i++)
		{
			if(num[i]!=4){
				num[i]++;
				for(int j=1;j<=9;j++)
				{
					if(num[j]<2)
					{
					}else{
						num[j]-=2;
						solve(&num,&ans,i);
						num[j]+=2;
					}
				}
				num[i]--;
			}
		}
		vector<int> tmp;
		for(int i=1;i<=9;i++)
		{
			if(ans[i]>0) tmp.push_back(i);
		}
		if(tmp.size()==0) cout<<0<<endl;
		else
		{
			for(int i=0;;i++)
			{
				cout<<tmp[i];
				if(i==tmp.size()-1)
				{
					cout<<endl;
					break;
				}
				cout<<' ';
			}
		}
	}
	return 0;
}