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

bool dfs(int *p, int k){
	if(k >= 4)
		return true;

	bool res = false;
	for(int i = 1; i < 10 - 2; ++i){
		if(p[i] && p[i + 1] && p[i + 2]){
			p[i]--; p[i + 1]--; p[i + 2]--;
			res |= dfs(p, k + 1);
			p[i]++; p[i + 1]++; p[i + 2]++;
		}
	}
	for(int i = 1; i < 10; ++i){
		if(p[i] >= 3){
			p[i] -= 3;
			res |= dfs(p, k + 1);
			p[i] += 3;
		}
	}
	
	return res;
}

int main() {
	string s;
	while(cin >> s){
		int n[16] = {0};
		vector<int> ans;
		for(int i = 0; i < s.size(); ++i){
			n[s[i] - '0']++;
		}
		for(int i = 1; i < 10; ++i){
			n[i]++;
			if(n[i] > 4){
				n[i]--;
				continue;
			}
			bool res = false;
			for(int j = 1; j < 10; ++j){
				if(n[j] >= 2){
					n[j] -= 2;
					res |= dfs(n, 0);
					n[j] += 2;
				}
				if(res)
					break;
			}
			if(res)
				ans.push_back(i);
			n[i]--;
		}
		if(ans.empty()){
			cout << "0" << endl;
		}
		else{
			for(const auto& v : ans){
				if(ans[0] != v)
					cout << " ";
				cout << v;
			}
			cout << endl;
		}
	}
	return 0;
}