#include <bits/stdc++.h>
using namespace std;

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

const int N = 15;
int c[N];
bool ans;

void dfs(int a, int b) {
	if(!a && !b) {
		ans = 1;
		return;
	}
	int i = find_if(c, c + N, [](int i) { return i > 0; }) - c;
	if(a) {
		if(c[i] >= 3) {
			c[i] -= 3;
			dfs(a - 1, b);
			c[i] += 3;
		}
		if(c[i] && c[i + 1] && c[i + 2]) {
			c[i] --; c[i + 1] --; c[i + 2] --;
			dfs(a - 1, b);
			c[i] ++; c[i + 1] ++; c[i + 2] ++;
		}
	}
	if(b && c[i] >= 2) {
		c[i] -= 2;
		dfs(a, b - 1);
		c[i] += 2;
	}
}

int main() {
	ios :: sync_with_stdio(0);

	for(string s; cin >> s; ) {
		memset(c, 0, sizeof c);
		for(char i : s)
			c[i - '0'] ++;
		vector <int> v;
		for(int i = 1; i <= 9; i ++) if(c[i] < 4) {
			c[i] ++;
			ans = 0;
			dfs(4, 1);
			if(ans)
				v.pb(i);
			c[i] --;
		}
		if(v.size() == 0)
			cout << "0\n";
		else {
			for(int x : v)
				cout << x << ' ';
			cout << '\n';
		}
	}

	return 0;
}