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

string s;
set<int> ans;

bool f(int x){
	return x != 0;
}

void solve(vector<int> cnt,int n, int i)
{
	if(count_if(cnt.begin(),cnt.end(),f) == 0){
		ans.insert(n);
		return;
	}
	int t = cnt[i];
	
	if(t >= 3){
		cnt[i] -= 3;
		if(cnt[i] == 0){
			solve(cnt,n,i + 1);
		} else if(min(cnt[i + 1],cnt[i + 2]) >= 1){
			cnt[i]--;
			cnt[i + 1]--;
			cnt[i + 2]--;
			solve(cnt,n,i + 1);
			cnt[i]++;
			cnt[i + 1]++;
			cnt[i + 2]++;
		}
		cnt[i] += 3;
		}
		
	if(min(cnt[i + 1],cnt[i + 2]) >= cnt[i]){
		cnt[i] -= t;
		cnt[i + 1] -= t;
		cnt[i + 2] -= t;
		solve(cnt,n,i + 1);
		cnt[i] += t;
		cnt[i + 1] += t;
		cnt[i + 2] += t;
	}
}

int main()
{
	while(getline(cin,s)){
		ans.clear();
		if(s == "0")break;
		vector<int> cnt(12);
		for(int i = 0; i < (int)s.size(); ++i){
			cnt[s[i] - '0']++;
		}
		for(int i = 1; i < 10; ++i){
			if(cnt[i] == 4)continue;
			cnt[i]++;
			for(int j = 1; j < 10; ++j){
				if(cnt[j] >= 2){
					cnt[j] -= 2;
					solve(cnt,i,1);
					cnt[j] += 2;
				}
			}
			cnt[i]--;
		}
		
		if(ans.size() == 0){
			cout << 0 << endl;
		} else {
			for(set<int>::iterator it = ans.begin(); it != ans.end(); ++it){
				if(it != ans.begin())cout << ' ';
				cout << *it;
			}
			cout << endl;
		}
	}
}