#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

typedef vector<int> vi;

bool rec(vi cur){
	int sum=0;
	for(auto &i:cur) sum+=i;
	if(sum<=2){
		for(auto &i:cur) if(i==2) return true;
		return false;
	}

	bool res=false;
	rep(i,7){
		if(cur[i]&&cur[i+1]&&cur[i+2]){
			vi next=cur;
			rep(j,3) next[i+j]--;
			res|=rec(next);
		}
	}
	rep(i,9){
		if(cur[i]>=3){
			vi next=cur;
			next[i]-=3;
			res|=rec(next);
		}
	}
	return res;
}

string s;

int main(void){
	while(cin >> s){
		if(cin.eof()) break;
		vi cur(9);
		rep(i,s.size()) cur[s[i]-'1']++;
		vi ans;
		rep(i,9){
			vi next=cur;
			next[i]++;
			bool ok=true;
			rep(j,9) if(next[j]>4) ok=false;
			if(!ok) continue;
			if(rec(next)) ans.push_back(i+1);
		}
		if(ans.size()==0)
			puts("0");
		else{
			rep(i,ans.size()) cout << (i?" ":"") << ans[i];
			cout << endl;
		}
	}
	return 0;
}