#include <iostream>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
int* calc(int a, vector<int> v1, vector<int> v2, int (&n)[10]) {
	int x;
	if(v1.size() > a) {
		x = v1[a];
		n[x]--, n[x+1]--, n[x+2]--;
	} else {
		x = v2[a - v1.size()];
		rep(j,3) n[x]--;
	}
	return n;
}

bool judge(int j, int k, int l, int m, vector<int> v1, vector<int> v2, int *n) {
	int nn[10];
	rep(i,10) {
		nn[i] = n[i];
	}
	calc(j,v1,v2, nn);
	calc(k,v1,v2, nn);
	calc(l,v1,v2, nn);
	calc(m,v1,v2, nn);
	bool f = 0;
	rep(i,10) {
		if(nn[i] < 0) {
			f = 0;
			break;
		}
		if(nn[i] == 2) f = 1;
	}
	if(f) return true;
	return false;
}
int main() {
	string s;
	while(cin >> s) {
		bool bl = 1;
		int n[10];
		rep(i,10) {
			n[i] = 0;
		}
		rep(i,s.length()) {
			n[s[i] - '0']++;
		}
		rep2(i,1,10) {
			n[i]++;
			bool f = 0;
			rep(j,10) {
				if(n[j] > 4) f = 1;
			}
			if(f) {
				n[i]--;
				continue;
			}
			vector<int> v1;
			rep2(j,1,8) {
				int c = min(n[j],min(n[j+1], n[j+2]));
				if(c > 0) {
					rep(k,c) {
						v1.push_back(j);
					}
				}
			}
			vector<int> v2;
			rep2(j,1,10) {
				if(n[j] >= 3) v2.push_back(j);
			}
			int len = v1.size() + v2.size();
			f = 0;
			rep(j,len) {	
				rep2(k,j+1,len) {
					rep2(l,k+1,len) {
						rep2(m,l+1,len) {
							if(judge(j, k, l, m, v1, v2, n)) {								
								if(bl) cout << i;
								else cout << " " << i;
								bl = 0;
								f = 1;
								break;
							}
						}
						if(f) break;
					}
					if(f) break;
				}
				if(f) break;
			}
			n[i]--;
		}
		if(bl) cout << 0 << endl;
		else cout << endl;
	}
	return 0;
}