#include<iostream>

using namespace std;

const int MAX_LINELEN = 14;
const int DIGIT_NUM = 10;

int puzzleCheck(int [], int, int, int *);
void checkNum(char *, int []);

int main(void)
{
	while( true ){
		int i;
		int isThisLineClear = 0;
		char lineData[MAX_LINELEN] = "";
		
		scanf("%s", lineData);
		if( strlen( lineData ) < 13){
			break;
		}

		for(i = 1; i <= DIGIT_NUM; i++){
			int j;
			int foundFlag = 0;
			int invalidPuzzle = 0;
			int num[DIGIT_NUM] = {0,};
			
			lineData[MAX_LINELEN - 1] = i + '0';
			checkNum(lineData, num);
			
			for(j = 0; j < DIGIT_NUM; j++){
				if(num[j] >= 5){
					invalidPuzzle = 1;
				}
			}
			if(invalidPuzzle){continue;}
			
			puzzleCheck(num, i, 0, &foundFlag);
			if(foundFlag){isThisLineClear = 1;}
		}
		if(isThisLineClear){
			printf("\b\n");
		}else{
			printf("0\n");
		}
	}
	return 0;
}

int puzzleCheck(int num[], int nowNumber, int twoPairFlag, int *foundFlag)
{
	int isComplete = 0;
	for(int i = 0; i < DIGIT_NUM; i++){
		if(num[i] == 0){
			isComplete++;
		}
	}
	if(isComplete == DIGIT_NUM && *foundFlag == 0){
		printf("%d ", nowNumber);
		*foundFlag = 1;
	}
	
	for(int i = 0; i < DIGIT_NUM; i++){
		if(num[i] >= 2 && twoPairFlag == 0){
			num[i] -= 2;
			puzzleCheck(num, nowNumber, 1, foundFlag);
			num[i] += 2;
		}
		if(num[i] >= 3){
			num[i] -= 3;
			puzzleCheck(num, nowNumber, twoPairFlag, foundFlag);
			num[i] += 3;
		}
		if(i <= DIGIT_NUM - 3){
			if(num[i] >= 1 && num[i+1] >= 1 && num[i+2] >= 1){
				num[i]--;num[i+1]--;num[i+2]--;
				puzzleCheck(num, nowNumber, twoPairFlag, foundFlag);
				num[i]++;num[i+1]++;num[i+2]++;
			}
		}
	}
	return 0;
}

void checkNum(char *lineData, int num[])
{
	const char digits[DIGIT_NUM] = "123456789";
	
	for(unsigned int i = 0; i < strlen(lineData); i++){
		for(int j = 0; j < DIGIT_NUM; j++){
			if(lineData[i] == digits[j]){
				num[j]++;
			}
		}
	}
}