#include<iostream>

using namespace std;

const int DIGIT_NUM = 9;
bool outputAdjst = false;

void puzzleCheck(int num[], int nowNumber, bool *bFound){
	int zeroCount = 0;
	int twoCount = 0;

	if( *bFound ) return ;

	for(int i = 0; i < DIGIT_NUM; i++){
		if( num[i] >= 3 ){
			num[i] -= 3;
			puzzleCheck(num, nowNumber, bFound);
			num[i] += 3;
			if( *bFound ) return ;
		}
	}

	for(int i = 0; i < DIGIT_NUM - 2; i++){
		if( num[i] >= 1 && num[i+1] >= 1 && num[i+2] >= 1 ){
			--num[i];--num[i+1];--num[i+2];
			puzzleCheck(num, nowNumber, bFound);
			++num[i];++num[i+1];++num[i+2];
			if( *bFound ) return ;
		}
	}
	for(int i = 1; i < DIGIT_NUM - 1; i++){
		if( num[i-1] >= 1 && num[i] >= 1 && num[i+1] >= 1 ){
			--num[i-1];--num[i];--num[i+1];
			puzzleCheck(num, nowNumber, bFound);
			++num[i-1];++num[i];++num[i+1];
			if( *bFound ) return ;
		}
	}
	for(int i = 2; i < DIGIT_NUM; i++){
		if( num[i-2] >= 1 && num[i-1] >= 1 && num[i] >= 1 ){
			--num[i-2];--num[i-1];--num[i];
			puzzleCheck(num, nowNumber, bFound);
			++num[i-2];++num[i-1];++num[i];
			if( *bFound ) return ;
		}
	}
	
	for(int i = 0; i < DIGIT_NUM; i++){
		switch( num[i] ){
			case 0:
				zeroCount++;
				break;
			case 2:
				twoCount++;
				break;
		}
	}
	if( twoCount == 1 && zeroCount == DIGIT_NUM - 1 ){
		if( outputAdjst ) cout << ' ' << nowNumber;
		else cout << nowNumber;
		*bFound = true;
		outputAdjst = true;
	}
	return ;
}

int main(void){
	while( true ){
		int num[DIGIT_NUM] = {0,};
		bool clear = false;
		bool end = false;

		outputAdjst = false;

		for(int i = 0; i < 13; i++){
			int d = 0;
			if( scanf("%1d", &d) != 1 ){
				end = true;
				break;
			}
			num[d-1]++;
		}

		if( end ) break;
		
		for(int i = 0; i < DIGIT_NUM; i++){
			bool found = false;
			bool invalid = false;
			
			if( i > 0 ) num[i - 1]--;
			num[i]++;

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

			if( found ) clear = true;
		}
		if( clear ) cout << '\n';
		else cout << "0\n";
	}
	return 0;
}