#include <iostream>
#include <string>
#include <algorithm>

using namespace std;


int solve(int *pnum, int len) {
	if (len == 0) {
		return 1;
	}

	for (int index = 1; index < 10; index++) {
		if (pnum[index] != 0) {
			if (pnum[index] >= 3) {
				pnum[index] -= 3;
				int result = solve(pnum, len - 3);
				pnum[index] += 3;
				if ( result == 1) {
					return 1;
				}
			}

			if (pnum[index] >= 2 && len % 3 == 2) {
				pnum[index] -= 2;
				int result = solve(pnum, len - 2);
				pnum[index] += 2;
				if (result == 1) {
					return 1;
				}
			}

			if (pnum[index] >= 1 && pnum[index + 1] >= 1 && pnum[index + 2] >= 1) {
				pnum[index] -= 1;
				pnum[index + 1] -= 1;
				pnum[index + 2] -= 1;
				int result = solve(pnum, len - 3);
				pnum[index] += 1;
				pnum[index + 1] += 1;
				pnum[index + 2] += 1;
				if (result == 1) {
					return 1;
				}
			}
		}
	}

	return 0;
}

int main(void) {
	int i,flag;
	string str;
	int num[12];

	while (cin >> str) {
		//cout << str << endl;
		flag = 0;
		for (i = 0; i < 12; i++) {
			num[i] = 0;
		}
       
		for (i = 0; i < 13; i++) {
			num[str[i] - '0']++;
		}

		for (i = 1; i < 10; i++) {
			if (num[i] == 4) {
				continue;
			}

			num[i]++;
			if (solve(num, 14) == 1) {
				if (flag == 1) {
					cout << " ";
				}
				cout << i;
				flag = 1;
			}
			num[i]--;
		}
		if (flag == 0) {
			cout << "0";
		}
		cout << endl;
		/*for (i = 1; i < 10; i++) {
			cout << endl << i << " : " << num[i] << endl;
		}*/
	}

	return 0;
}


