#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int n[14];

bool solve(int a){
	int raw[14];
	sort(n, n+14);
	// save raw data
	for (int i = 0; i < 14; i++) {
		raw[i] = n[i];
	}
	// find 5 same
	for (int i = 4; i < 14; i++) {
		if(n[i] == n[i-1] && n[i] == n[i-2] && n[i] == n[i-3] && n[i] == n[i-4]){
			return false;
		}
	}
	// find pair
	bool pair[10];
	for (int i = 0; i < 10; i++) {
		pair[i] = false;
	}
	for (int i = 0; i < 13; i++) {
		if (n[i] == n[i+1]) {
			pair[n[i]] = true;
		}
	}
	// main
	for (int k = 1; k <= 9; k++) {
		if(!pair[k]){
			continue;
		}
		for (int j = 0; j < 14; j++) {
			n[j] = raw[j];
		}
		// pair
		for (int j = 0; j < 13; j++) {
			if(n[j] == k && n[j] == n[j+1]){
				n[j] = n[j+1] = -1;
				break;
			}
		}
		// same
		for (int i = 2; i < 14; i++) {
			if(n[i] == n[i-1] && n[i] == n[i-2]){
				n[i] = n[i-1] = n[i-2] = -1;
			}
		}
		// sequence
		int first, second, third;
		for (int i = 0; i < 14; i++) {
			first = i;
			second = third = -1;
			for (int j = i; j < 14; j++) {
				if(second == -1 && n[first]+1 == n[j]){
					second = j;
				}else if(second != -1 && third == -1 && n[first]+2 == n[j]){
					third = j;
				}
			}
			if(second != -1 && third != -1){
				n[first] = n[second] = n[third] = -1;
			}
		}
		
		bool result = true;
		for (int i = 0; i < 14; i++) {
			if(n[i] != -1){
				result = false;
			}
		}
		if(result){
			return true;
		}
	}
}

int main(){
	string str;
	bool hasAns;
	while(cin >> str){
		hasAns = false;
		for (int i = 1; i <= 9; i++) {
			for (int j = 0; j < str.size(); j++) {
				n[j] = str[j] - '0';
			}
			n[13] = i;
			if(solve(i)){
				if(!hasAns){
					cout << i;
					hasAns = true;
				}else{
					cout << " " << i;
				}
			}
		}
		if(!hasAns){
			cout << 0 << endl;
		}else{
			cout << endl;
		}
	}
	return 0;
}