#include<iostream>
#include<vector>
#include<queue>
#include<string>
using namespace std;
queue<vector<int> >Q;
string S; int p[14];
int main() {
	while (cin >> S) {
		vector<int>s; int g[10] = { 0,0,0,0,0,0,0,0,0,0 };
		for (int i = 0; i < 13; i++) {
			p[i] = S[i] - '0'; g[p[i]]++;
		}
		for (int i = 0; i < 10; i++)s.push_back(g[i]);
		s.push_back(1); int f[10] = { 0,0,0,0,0,0,0,0,0,0 };
		for (int h = 1; h < 10; h++) {
			s[h]++; Q.push(s); int OK = 0;
			while (!Q.empty()) {
				vector<int>t = Q.front(), u; Q.pop(); int sum = 0;
				for (int i = 0; i < 10; i++) sum += t[i];
				if (sum == 0)OK = 1;
				for (int i = 0; i < 10; i++) {
					if (t[i] >= 2 && t[10] >= 1) { u = t; u[i] -= 2; u[10] = 0; Q.push(u); }
					if (t[i] >= 3) { u = t; u[i] -= 3; Q.push(u); }
				}
				for (int i = 0; i < 8; i++) {
					if (t[i] >= 1 && t[i + 1] >= 1 && t[i + 2] >= 1) {
						u = t; u[i] -= 1; u[i + 1] -= 1; u[i + 2] -= 1; Q.push(u);
					}
				}
			}
			for (int i = 0; i < 10; i++) {
				if (s[h] >= 5)OK = 0;
			}
			f[h] = OK; s[h]--;
		}
		int V = 0;
		for (int i = 1; i < 10; i++) {
			if (f[i] == 1) {
				if (V >= 1) { cout << ' '; }
				cout << i; V++;
			}
		}
		if (V == 0)cout << '0';
		cout << endl;
	}
	return 0;
}