#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	string s;
	while (cin >> s) {
		vector<int> d(10, 0);
		for (int i = 0; i < s.size(); i++) {
			d[s[i]-'0']++;
		}
		/*for (int i = 0; i < 10; i++) {
			cout << i << ' ' << d[i] << endl;
		}*/
		vector<int> v;
		for (int i = 1; i < 10; i++) {
			if (d[i] < 4) {
				vector<int> e = d;
				e[i]++;
				/*for (int j = 1; j < 10; j++) {
					cout << j << ' ' << e[j] << endl;
				}*/
				for (int j = 1; j < 10; j++) {
					if (e[j] > 1) {
						bool h = true;
						vector<int> f = e;
						f[j] -= 2;
						//cout << i << ' ' << j << ' ';
						//cout << f[1] << ' ';
						for (int k = 1; k < 10; k++) {
							if (f[k] >= 3) {
								f[k] -= 3;
								k--;
							} else if (f[k] == 0) {
							} else if (k < 8) {
								if (f[k] == 1 && f[k+1] >= 1 && f[k+2] >= 1) {
									f[k]--;
									f[k+1]--;
									f[k+2]--;
								} else if (f[k] == 2 && f[k+1] >= 2 && f[k+2] >= 2) {
									f[k] -= 2;
									f[k+1] -= 2;
									f[k+2] -= 2;
								} else {
									//cout << k << endl;
									h = false;
									break;
								}
							} else {
								//cout << k << endl;
								h = false;
								break;
							}
						}
						if (h) {
							v.push_back(i);
							break;
						}
					}
				}
			}
		}
		if (v.size() == 0) {
			cout << 0 << endl;
		} else {
			cout << v[0];
			for (int i = 1; i < v.size(); i++) {
				cout << ' ' << v[i];
			}
			cout << endl;
		}
	}
	return 0;
}