#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int p[10];

bool f(int q[10],bool a){
	int r[10];
	int i;
	for(i=0;i<10;i++)r[i]=q[i];
	for(i=0;i<10;i++){
		if(r[i])break;
	}
	if(i==10)return true;
	if(r[i]>=3){
		r[i]-=3;
		if(f(r,a))return true;
		r[i]+=3;
	}
	if(a==false&&r[i]>=2){
		r[i]-=2;
		if(f(r,true))return true;
		r[i]+=2;
	}
	if(i<=7&&r[i]&&r[i+1]&&r[i+2]){
		r[i]--;
		r[i+1]--;
		r[i+2]--;
		if(f(r,a))return true;
	}
	return false;
}

int main() {
	string str;
	while(cin>>str){
		memset(p,0,sizeof(p));
		int i;
		for(i=0;i<str.size();i++){
			p[str[i]-'0']++;
		}
		int num=0;
		for(i=1;i<10;i++){
			if(p[i]==4)continue;
			p[i]++;
			if(f(p,false)){
				if(num!=0)cout<<" ";
				cout<<i;
				num++;
			}
			p[i]--;
		}
		if(num==0)cout<<0;
		cout<<endl;
	}
	return 0;
}