#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;


bool check(vi v){
	FOR(i, 1, 10){
		if(v[i] < 2) continue;
		vi num = v;
		num[i] -= 2;
		FOR(j, 3, 10){
			while(num[j]&&num[j-1]&&num[j-2]){
				if(num[j-2]%3 == 0) break;
				num[j]--;
				num[j-1]--;
				num[j-2]--;
			}
		}
		bool ok = true;
		rep(j, 10){
			if(num[j]&&(num[j]!=3)) ok = false;
		}
		if(ok) return true;
	}

	return false;
}

int main(){
	string s;
	while(cin >> s){
		vi num(10, 0);
		rep(i, s.size()){
			num[s[i]-'0']++;
		}
		vector<int> ans;
		FOR(i, 1, 10){
			if(num[i] >= 4) continue;
			num[i]++;
			if(check(num)) ans.push_back(i);
			num[i]--;
		}
		if(ans.empty()) ans.push_back(0);
		rep(i, ans.size()) cout << (i?" ":"") << ans[i];
		cout << endl;
	}

	return 0;
}