#include<iostream>
#include<cstring>

using namespace std;

const int MAX_LINELEN = 15;
const int DIGIT_NUM = 9;
bool outputAdjst = false;

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

int main(void){
	while( true ){
		int isThisLineClear = 0;
		char lineData[MAX_LINELEN] = "";
		outputAdjst = false;
		
		scanf("%13s", lineData);
		if( strlen( lineData ) < 13) break;
		
		for(int i = 0; i < DIGIT_NUM; i++){
			int foundFlag = 0;
			int invalidPuzzle = 0;
			int num[DIGIT_NUM] = {0,};
			
			lineData[MAX_LINELEN - 2] = i + 1 + '0';
			
			checkNum(lineData, num);

			for(int j = 0; j < DIGIT_NUM; j++){
				if(num[j] >= 5){
					invalidPuzzle = 1;
				}
			}
			if( invalidPuzzle ) continue;
			
			puzzleCheck(num, i + 1, 0, &foundFlag);

			if( foundFlag ) isThisLineClear = 1;
		}
		if( isThisLineClear ) cout << "\n";
		else cout << "0\n";
	}
	return 0;
}

int puzzleCheck(int num[], int nowNumber, int twoPairFlag, int *foundFlag){
	if( *foundFlag ) return 0;

	if( !twoPairFlag ){
		for(int i = 0; i < DIGIT_NUM; i++){
			if( num[i] >= 2 ){
				twoPairFlag = 1; num[i] -= 2;
				puzzleCheck(num, nowNumber, twoPairFlag, foundFlag);
				twoPairFlag = 0; num[i] += 2;
			}
		}
	}else{
		bool bComplete = true;
		
		for(int i = 0; i < DIGIT_NUM; i++){
			if( num[i] >= 3 ){
				num[i] -= 3;
				puzzleCheck(num, nowNumber, twoPairFlag, foundFlag);
				num[i] += 3;
			}
		}
		for(int i = 0 ; i < DIGIT_NUM; i++){
			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];
				}
			}
		}
		for(int i = 0; i < DIGIT_NUM; i++) if( num[i] != 0 ) bComplete = false;
		
		if( bComplete ){
			if( outputAdjst ) cout << ' ' << nowNumber;
			else cout << nowNumber;
			*foundFlag = 1;
			outputAdjst = true;
		}
	}
	return 0;
}

void checkNum(char *lineData, int num[]){
	unsigned int len = strlen(lineData);
	const char digits[DIGIT_NUM+1] = "123456789";

	for(unsigned int i = 0; i < len; i++){
		for(unsigned int j = 0; j < strlen(digits); j++){
			if(lineData[i] == digits[j]){
				num[j]++;
				break;
			}
		}
	}
}