#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

bool judge(string s, bool head)
{
	if (s.empty()) return true;
	
	char c = s[0];
	bool ff = true, fff = true, ffff = true;
	string ss = s, sss = s, ssss = s;
	
	for (int i = 0; i < 3; i++){
		if (ss.find(c) == -1){ ff = false; break; }
		ss.erase(ss.find(c), 1);
	}
	if (ff) ff = judge(ss, head);
	
	for (int i = 0; i < 3; i++){
		if (sss.find(c+i) == -1){ fff = false; break; }
		sss.erase(sss.find(c+i), 1);
	}
	if (fff) fff = judge(sss, head);
	
	if (!head){
		for (int i = 0; i < 2; i++){
			if (ssss.find(c) == -1){ ffff = false; break; }
			ssss.erase(ssss.find(c), 1);
		}
		if (ffff) ffff = judge(ssss, true);
	}
	else ffff = false;
	
	return ff || fff || ffff;
}

int main(void)
{
	string s;
	while (cin >> s){
		bool flag = false;
		vector <int> v;
		for (char c = '1'; c <= '9'; c++){
			string ss = s;
			ss += c;
			if (static_cast <int> (count(ss.begin(), ss.end(), c)) > 4) continue;
			sort(ss.begin(), ss.end());
			if (judge(ss, false))
			{
				v.push_back(c - '0');
				flag = true;
			}
		}
		if (!flag) cout << "0" << endl;
		else {
			for (int i = 0; i < v.size(); i++){
				cout << v[i];
				if (i+1==v.size()) puts("");
				else cout << " ";
			}
		}
	}
	
	return 0;
}