#include <string>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <algorithm>
#include <numeric>
#include <iostream>

using namespace std;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

bool solve(vector<char>& s,int sz){
	if(sz == 0) return true;
	for (int i = 1; i <= 9; i++){
		int cnt = s[i];
		if(cnt >= 5)
			return false;
		if(cnt >= 2){
			if(sz % 3 == 2){
				s[i] -= 2;
				if(solve(s,sz - 2)) return true;
				s[i] += 2;
			}
		}
		if(cnt >= 3){
				s[i] -= 3;
				if(solve(s,sz - 3)) return true;
				s[i] += 3;
		}
		if(i <= 7 && s[i] > 0 && s[i+1] > 0 && s[i+2] > 0){
			s[i]--; s[i+1]--; s[i+2]--;
			if(solve(s,sz - 3)) return true;
			s[i]++; s[i+1]++; s[i+2]++;
		}
	}

	return false;
}

int main()
{
	string s;
	while(cin>>s){
		vector<char> sv(10);
		for (int i = 0; i < (int)s.length(); i++) sv[s[i]-'0']++;
		vector<char> ans;
		for (int i = 1; i <= 9; i++){
			vector<char> arg(sv);
			arg[i]++;
			if(solve(arg,14))
				ans.push_back(i);
		}
		if(ans.empty())
			puts("0");
		else 
			for (int i = 0; i < (int)ans.size(); i++){
				printf("%c%c",ans[i] + '0' ,i == (int)ans.size()-1 ? '\n' : ' ');
			}
	}

}