#include <stdio.h>
#include <string.h>

bool check(int count[], int n)
{
	if (n == 0){
		return (true);
	}
	
	for (int i = 1; i <= 9 - 2; i++){
		if (count[i] > 0 && count[i + 1] > 0 && count[i + 2] > 0){
			count[i]--;
			count[i + 1]--;
			count[i + 2]--;
			if (check(count, n - 3) == true){
				return (true);
			}
			count[i]++;
			count[i + 1]++;
			count[i + 2]++;
		}
	}
	for (int i = 1; i <= 9; i++){
		if (count[i] >= 3){
			count[i] -= 3;
			if (check(count, n - 3) == true){
				return (true);
			}
			count[i] += 3;
		}
	}
	
	return (false);
}

int main(void)
{
	char in[256];
	int count[10];
	
	while (fgets(in, 256, stdin) != NULL){
		
		memset(count, 0, sizeof(count));
		for (int i = 0; i < 13; i++){
			count[in[i] - '0']++;
		}
		int temp[10];
		bool start = true;
		
		memcpy(temp, count, sizeof(count));
		for (int i = 1; i <= 9; i++){
			memcpy(count, temp, sizeof(count));
			if (count[i] < 4){
				count[i]++;
				
				bool flag = false;
				for (int j = 1; j <= 9; j++){
					if (count[j] >= 2){
						count[j] -= 2;
						if (check(count, 12) == true){
							flag = true;
							break;
						}
						count[j] += 2;
					}
				}
				if (flag == true){
					if (start == true){
						start = false;
						printf("%d", i);
					}
					else {
						printf(" %d", i);
					}
				}
				count[i]--;
			}
		}
		if (start == true){
			printf("0");
		}
		puts("");
	}
	
	return (0);
}