#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<int> hand;
vector<int> org;

bool judgeHand() {
	for (int i = 1; i <= 9; i++) {
		if (hand[i] < 0) return false;
		if (hand[i] >= 3) hand[i] -= 3;
		if (hand[i] != 0) {
			if (i > 7) return false;
			hand[i + 1] -= hand[i];
			hand[i + 2] -= hand[i];
			hand[i] = 0;
		}
	}
	return true;
}

bool ok(int n) {
	for (int i = 1; i <= 9; i++) {
		hand = org;
		hand[n]++;
		if (hand[i] >= 2) {
			hand[i] -= 2;
			if (judgeHand()) return true;
		}
	}
	return false;
}

int main () {
	string str;
	while (cin >> str) {
		org = vector<int>(12, 0);
		for (int i = 0; i < 13; i++) {
			org[str[i] - '0']++;
		}
		bool first = true;
		for (int i = 1; i <= 9; i++) {
			hand = org;
			if (hand[i] < 4 && ok(i)) {
				if (!first) cout << ' ';
				else first = false;
				cout << i;
			}
		}
		if (first) cout << 0;
		cout << endl;
	}
	return 0;
}