#include<algorithm>
#include<iostream>
#include<numeric>
#include<vector>
#include<string.h>

void solve( std::vector<int> v, int n, bool ans[] )
{
	if( !std::accumulate( v.begin(), v.end(), 0 ) ){
	 	ans[n] = true;
		return;
	}
	
	for( int i = 1; i <= 9; i++ ){
	 	if( v[i] >= 3 ){
		 	v[i] -= 3;
			solve( v, n, ans );
			v[i] += 3;
		}
	}
	
	for( int i = 1; i <= 7; i++ ){
	 	if( v[i] && v[i+1] && v[i+2] ){
		 	v[i]--;
			v[i+1]--;
			v[i+2]--;
			solve( v, n, ans );
			v[i]++;
			v[i+1]++;
			v[i+2]++;
		}
	}
	
	return;
}

int main()
{
	char str[20];

	while( std::cin >> str ){
		std::vector<int> v;
		bool ans[10] = {0};
		
		for( int i = 0; i < 10; i++ ) v.push_back( 0 );
		
	 	for( int i = 0; i < strlen( str ); i++ ){
			v[ str[i] - '0' ]++;
		}
		
		for( int i = 1; i <= 9; i++ ){
			if( v[i] == 4 ) continue;
			else{
				v[i]++;
				for( int j = 1; j <= 9; j++ ){
					if( v[j] >= 2 ){
					 	v[j] -= 2;
						solve( v, i, ans );
						v[j] += 2;
					}
				}
				v[i]--;
			}
		}
		
		if( !std::count( ans + 1, ans + 10, true ) ){
		 	std::cout << 0 << std::endl;
		}
		else{
			bool flag = true;
		 	for( int i = 1; i <= 9; i++ ){
				if( ans[i] ){
					if( flag ){
						flag = false;
					}
					else{
						std::cout << " ";
					}
					std::cout << i;
				}
			}
			std::cout << std::endl;
		}
	}

 	return 0;
}