//0043 Puzzle
//vñF`CcÌãªèvð¦¹

#include<cstdio>
#include<algorithm>

using namespace std;

//evª éÂA4ÚÈãÍg¦È¢
int haiCount[10] = {0};

bool f(int mentsuCount)
{
	if(mentsuCount == 4)
		return true;
	int i;
	bool result;
	//Æè ¦¸AÔÉR[cÆ¼èµÄÊqðìé
	for(i = 1; i <= 9; i++)
	{
		if(haiCount[i] >= 3)
		{
			haiCount[i] -= 3;
			result = f(mentsuCount+1);
			haiCount[i] += 3;
			if(result)
			{
				return true;
			}
		}
	}
	//ÍAWcÆ¼èµÄÊqðìé
	for(i = 1; i <= 7; i++)
	{
		if(haiCount[i] && haiCount[i+1] && haiCount[i+2])
		{
			haiCount[i]--, haiCount[i+1]--, haiCount[i+2]--;
			result = f(mentsuCount+1);
			haiCount[i]++, haiCount[i+1]++, haiCount[i+2]++;
			if(result)
			{
				return true;
			}
		}
	}
	return false;
}

int main(void)
{
	const int N =14;
	char hai[N];
	int i;
	int head;
	bool canOut;	//ãªêéH
	int outCount;	//ãªêévÌÂ

	while(scanf("%s", hai) == 1)
	{
		fill(haiCount, haiCount+10, 0);
		for(i = 0; i < N-1; i++)
			haiCount[hai[i]-'0']++;

		outCount = 0;

		//15ÚÌvðø­
		for(i = 1; i <= 9; i++)
		{
			canOut = false;
			if(haiCount[i] ==4)
				continue;

			//g¤vªêÂ¦Üµ½
			haiCount[i]++;

			//Ü¸Íª©çÅèµÄ¢«Üµå¤
			for(head = 1; head <= 9; head++)
			{
				if(haiCount[head] < 2)
					continue;

				haiCount[head] -= 2;
				canOut = f(0);
				haiCount[head] += 2;
				if(canOut)
				{
					break;
				}
			}

			if(canOut)
			{
				if(outCount++)
					printf(" %d", i);
				else
					printf("%d", i);
			}

			//gíÈ­ÈèÜµ½
			haiCount[i]--;
		}
		if(!outCount)
			puts("0");
		else
			putchar('\n');
	}
	return 0;
}