#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cstring>

using namespace std;

bool wrapper2(int seq[], int len, int i, int j, int k);

void printv(int v[], int len) {
	for (int i = 0; i < len; i++)
		cout << v[i];
	cout << endl;
}

bool check(int seq[], int len) {
	if (len == 0)
		return true;
	else
		for (int i = 0; i < len - 2; i++) {
			int a = seq[i];
			for (int j = i + 1; j < len - 1; j++) {
				int b = seq[j];
				for (int k = j + 1; k < len; k++) {
					int c = seq[k];
					if ((a == b && b == c) || (a+1 == b && b+1 == c)) {
						if (wrapper2(seq, len, i, j, k) == true)
							return true;
					}
				}
			}
		}
	return false;
}

bool wrapper1(int seq[14], int i, int j) {
	seq[i] = seq[j] = 0;
	sort(seq, seq + 14);
	return check(&seq[2], 12);
}

bool wrapper2(int seq[], int len, int i, int j, int k) {
	seq[i] = seq[j] = seq[k] = 0;
	sort(seq, seq + len);
	return check(&seq[3], len - 3);
}

bool check14(int seq[14]) {
	sort(seq, seq + 14);
	printv(seq, 14);
	for (int i = 1; i <= 9; i++)
		for (int j = 0; j < 13; j++) {
			if (seq[j] == i && seq[j+1] == i) {
				if (wrapper1(seq, j, j+1) == true)
					return true;
				break;
			}
		}
	return false;
}

int solve(int seq[14]) {
	int ans = 0;
	for (int i = 1; i <= 9; i++) {
		int same = 0;
		for (int j = 0; j < 13; j++)
			if (seq[j] == i)
				same++;
		if (same >= 4)
			continue;
		seq[13] = i;
		if (check14(seq) == true)
			ans |= (0x01 << i);
	}
	return ans;
}

int main() {
	string str;
	while (cin >> str) {
		int seq[14] = {};
		for (int i = 0; i < 13; i++) {
			char c = str[i];
			seq[i] = atoi(&c);
		}
		int ans = solve(seq);
		if (ans == 0)
			cout << 0 << endl;
		else {
			int ifs = 1;
			for (int i = 1; i <= 9; i++) {
				if (ans & (0x01 << i)) {
					if (ifs == 0)
						cout << " ";
					cout << i;
					ifs = 0;
				}
			}
			cout << endl;
		}
	}
	return 0;
}