#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


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


bool check(vi a) {
	int n = a.size();
	rep (i, n) rep (j, n) if (i < j) if (a[i] == a[j]) {
		vi h(11, 0);
		rep (k, n) {
			h[a[k]]++;
			if (h[a[k]] == 5) return false;
		}
		h[a[i]] -= 2;
		rep (k, 9) {
			if (h[k + 1] >= 3) h[k + 1] -= 3;
			if (h[k + 1] <= 2) {
				if (k >= 8) continue;
				if (h[k + 1] >= 1 && h[k + 2] >= 1 && h[k + 3] >= 1) {
					h[k + 1]--;
					h[k + 2]--;
					h[k + 3]--;
				}
			}
			if (h[k + 1] <= 1) {
				if (k >= 8) continue;
				if (h[k + 1] >= 1 && h[k + 2] >= 1 && h[k + 3] >= 1) {
					h[k + 1]--;
					h[k + 2]--;
					h[k + 3]--;
				}
			}
		}
		bool ok = true;
		rep(i, 9) ok &= (h[i + 1] == 0);
		if (ok) return true;
	}
	return false;
}

int main() {
	for (string s; cin >> s; ) {
		vi a;
		rep(i, 13) a.pb(s[i] - '0');
		vi ans;
		rep (i, 9) {
			vi b = a;
			b.pb(i + 1);
			sort(all(b));
			if (check(b)) ans.pb(i + 1);
		}
		if (ans.size() == 0) cout << 0 << endl;
		else {
			rep (i, ans.size()) {
				if (i == ans.size() - 1) cout << ans[i] << endl;
				else cout << ans[i] << ' ';
			}
		}
	}
	
	return 0;
}