#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>
#include <fstream>

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 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#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;
bool f, f2;

void solve(int num, int co[]){
	if (num == 10){
		REP(i, 10){
			if (co[i] != 0)return;
		}
		f = 1;
		return;
	}

	if (co[num] >= 3){
		co[num] -= 3;
		if (co[num] > 0)solve(num, co);
		else solve(num + 1, co);
		co[num] += 3;
	}

	if (f2&&co[num] >= 2){
		co[num] -= 2;
		f2 = 0;
		if (co[num] > 0)solve(num, co);
		else solve(num + 1, co);
		co[num] += 2;
		f2 = 1;
	}

	if (num + 2 <= 9){
		if (co[num] >= 1 && co[num + 1] >= 1 && co[num + 2] >= 1){
			co[num]--;
			co[num + 1]--;
			co[num + 2]--;
			if (co[num] > 0)solve(num, co);
			else solve(num + 1, co);
			co[num]++;
			co[num + 1]++;
			co[num + 2]++;
		}
	}

	solve(num + 1, co);
}


int main(){
	while (cin >> s){
		int co[10] = {};
		V ans;
		REP(i, s.size()){
			co[s[i] - '0']++;
		}
		FOR(i, 1, 10){
			f = 0;
			f2 = 1;
			co[i]++;

			if (co[i] <= 4)solve(1, co);

			if (f)ans.push_back(i);
			co[i]--;
		}
		if (ans.size() == 0){
			cout << 0 << endl;
		}
		else{
			REP(i, ans.size()){
				if (i == 0)cout << ans[i];
				else cout << " " << ans[i];
			}
			cout << endl;
		}
	}
}