#include <iostream>
#include <cstring>

using namespace std;
/*
void swap(char& x, char &y)
{
	char tmp = x; x = y; y = tmp;
}

void sort(char a[])
{
	for (int i=0; i<15; i++) {
		for (int j=14; j>i; j--) {
			if (a[j-1] > a[j]) swap(a[j-1], a[j]);
		}
	}
}
*/
bool isWin(int p[], int depth)
{
	if (depth == 4) {
		for (int i=1; i<=9; i++) {
			if (p[i]==2) return true;
		}
		return false;
	}
	else { // depth < 4
		for (int i=1; i<=9; i++) {
			if (p[i]>=3) {
				p[i] -= 3;
				bool success = isWin(p, depth+1);
				p[i] += 3;
				if (success) return true;
			}
		}
		for (int i=1; i<=7; i++) {
			if (p[i]>0 && p[i+1]>0 && p[i+2]>0) {
				p[i]--; p[i+1]--; p[i+2]--;
				bool success = isWin(p, depth+1);
				p[i]++; p[i+1]++; p[i+2]++;
				if (success) return true;
			}
		}
		return false;
	}
}

int main()
{
	char hand[14];
	
	while ( cin >> hand ) {
		int count_pai[10] = {0};
		for (int i=0; i<13; i++) count_pai[hand[i]-'0']++;
		bool first_output = true;
		for (int pai=1; pai<=9; pai++) {
			if (count_pai[pai] == 4) continue;
			count_pai[pai]++;
			if ( isWin(count_pai, 0) ) {
				if (first_output) first_output = false;
				else cout << " ";
				cout << pai;
			}
			count_pai[pai]--;
		}
		if ( first_output ) cout << 0;
		cout << endl;
	}
			
	return 0;
}