#include<stdio.h>

#define AGARI 14
#define NUM 10
#define ON  1
#define OFF 0

	int count_num(int count_memory[NUM], char pz_char[NUM]);
int puzzle_flag(int count[],int count_memory[]);

int main(void)
{
	char pz_char[AGARI + 1];
	int  i = 0, j = 0, k = 0;
	int  count[ NUM ]={0};/*配列の中身が番号でいくつ入ってるか*/
	int count_memory[NUM]={0};
	int  flag[ NUM ];
	int  c = OFF;

	for(i = 1; i < AGARI+1 ; i++)
	{
		pz_char[i] = '\0';
	}
	while(scanf("%s", pz_char) != EOF)
	{		
		for(i = 1; i < NUM ; i++)/*最後の牌の探索*/
		{
			
			c = OFF;
			pz_char[AGARI - 1] = 0x30 + i;/*上がりであるかどうかの数字の代入*/
			c = count_num(count_memory, pz_char);/*１から９のそれぞれ同じ数字のカウント*/
			if(c == ON)
			{
				continue;
			}

			/*printf("%d\n",i);*/
			/*for(j = 1 ;j < NUM ; j++)
			{
				count[j] = count_memory[j];
			}*/
			

			flag[i] = puzzle_flag(count, count_memory);/*パズルの完完成があるかないか*/
			
		}

		/*----------------output------------*/
		/*printf("\n");*/
		c = ON;
		int a = 0;
		for(i = 1; i < NUM; i++)
		{
			if(flag[i] == ON)
			{
				a = i;
			}
			
		}for(i = 1; i < NUM; i++)
		{
			if(flag[i] == ON)
			{
				printf("%d",i);
				c = OFF;
				if(a != i)
				{
					printf(" ");
				}
				else
				{
					printf("\n");
				}
			}
			
		}
		if(c == ON)
		{
			printf("0\n");
		}
	}
	return 0;
}
int count_num(int count_memory[NUM], char pz_char[NUM])
{
	int i = 0, j = 0;
	int flag = OFF;

	/*printf("char=====%s\n",pz_char);*/
	for(i = 1 ; i < NUM; i++)
	{
		count_memory[i] = 0;
		for(j = 0; j < AGARI ; j++)
		{
			if(i == pz_char[j] - 0x30)
			{
				count_memory[i]++;
			}
		}
		/*printf("%d ",count_memory[i]);*/
	}
	/*printf("----------\n");*/
	for(i = 1 ; i < NUM; i++)
	{
		if(count_memory[i] > 4)
		{
			flag = ON;
		}
		/*printf("count[%d] = %d\n",i, count[i]);*/
	}
	if(flag == ON)
	{
		return ON;
	}
	else
	{
		return OFF;
	}
}

int puzzle_flag(int count[],int count_memory[])
{
	int i = 0, j = 0, k = 0;
	int flag = 0;

	for(i = 1; i < NUM; i++)
	{
		flag = ON;
		
		for(j = 1 ;j < NUM ; j++)
		{
			count[j] = count_memory[j];
			/*printf("%d ",count_memory[j]);*/
		}
		/*printf("\n");*/
		if(count[i] >= 2)
		{

			/*printf("i ========== %d \n", i);*/
			count[i] -= 2;
			for(j = 1; j < NUM; j++)
			{
				if(count[j] == 0)
				{	
					continue;	
				}
				else if(count[j] == 1 || count[j] == 2)
				{
					if(j < 8)
					{
						
						if(count[j + 1] > 0 && count[j + 2] > 0)
						{
							while(count[j] != 0)
							{
								for(k = j; k < j+ 3; k++)
								{
									count[k] -= 1;
								}
							}
						}
						else
						{
							break;
						}
					}
				}
				else if(count[j] == 3)
				{
					count[j] -= 3;
				}
				else if(count[j] == 4)
				{
					count[j] -= 3;
					if(j < 8 && count[j + 1] > 0 && count[j + 2] > 0)
					{
						for(k = j; k < j + 3; k++)
						{
							count[k] -= 1;
						}
					}
					else
					{
						break;
					}
				}
	
					
			}
		}
		/*printf("i========%d\n",i);*/
		for(j = 1; j < NUM; j++)
		{
			/*printf("count[%d] = %d \n", j, count[j]);*/
			if(count[j] != 0)
			{
				flag = OFF;
			}
		}
		if(flag == ON)
		{
			/*printf("aaaaaaaaaaaa\n");*/
			break;
		}
	}
	if(flag == ON)
	{
		return ON;
	}else
	{
		return OFF;
	}
}