#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;
int f[10];

bool check(int co[]){
	int table[10];
	for (int i = 1; i < 10; i++){
		FOR(j, 1, 10)table[j] = co[j];

		//FOR(j, 1, 10){
		//	REP(k, table[j]){
		//		cout << j;
		//	}
		//}
		//cout << endl;

		if (table[i] >= 2){
			//cout << i << endl;
			table[i] -= 2;
			for (int j = 1; j < 10; j++){
				if (table[j] >= 3)table[j] -= 3;
			}
			for (int j = 1; j < 8; j++){
				while (table[j]>0){
					if (table[j + 1] == 0 || table[j + 2] == 0)break;
					else{
						table[j]--;
						table[j + 1]--;
						table[j + 2]--;
					}
				}
			}
			for (int j = 1; j < 10; j++){
				if (table[j] > 0)break;
				if (j == 9)return true;
			}
			table[i] += 2;
		}
	}
	return false;
}

int main(){
	while (cin >> s){
		int co[100] = {};
		fill(f, f + 10, 0);
		V ans;
		REP(i, s.size()){
			co[s[i] - '0']++;
			if (co[s[i] - '0'] == 4)f[s[i] - '0'] = 1;
		}
		FOR(i, 1, 10){
			if (f[i])continue;
			co[i]++;
			if (check(co)){
				ans.push_back(i);
			}
			co[i]--;
		}
		if (ans.empty())cout << 0 << endl;
		else{
			REP(i, ans.size()){
				if (i == 0)cout << ans[i];
				else cout << " " << ans[i];
			}
			cout << endl;
		}
	}
}