#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

typedef map<int, int> Num;

int check2(Num a) {
	int sum = 0;
	for (int i = 1; i <= 9; i++)
		sum += a[i];
	return sum;
}

void check1(Num a, int n, int *ans) {
	if (check2(a) == 0) {
		*ans |= (0x01 << n);
		return;
	}

	for (int i = 1; i <= 9; i++) {
		if (a[i] >= 3) {
			a[i] -= 3;
			check1(a, n, ans);
			a[i] += 3;
		}
	}

	for (int i = 3; i <= 9; i++) {
		if (a[i-2] && a[i-1] && a[i]) {
			a[i-2] -= 1;
			a[i-1] -= 1;
			a[i] -= 1;
			check1(a, n, ans);
			a[i-2] += 1;
			a[i-1] += 1;
			a[i] += 1;
		}
	}
}

int solve(Num a) {
	int ans = 0;
	for (int i = 1; i <= 9; i++) {
		if (a[i] == 4) continue;

		a[i]++;
		for (int j = 1; j <= 9; j++)
			if (a[j] > 1) {
				a[j] -= 2;
				check1(a, i, &ans);
				a[j] += 2;
			}
		a[i]--;
	}
	return ans;
}

int main() {
	string str;
	while (cin >> str) {
		Num a;
		for (int i = 1; i <= 9; i++)
			a[i] = 0;
		for (int i = 0; i < str.size(); i++) {
			int s = str[i] - '0';
			a[s]++;
		}
		int ans = solve(a);
		if (ans == 0)
			cout << 0 << endl;
		else {
			int ifs = 0;
			for (int i = 1; i <= 9; i++) {
				if (ans & (0x01 << i))
					cout << ((ifs++) ? " " : "") << i;
			}
			cout << endl;
		}
	}
	return 0;
}