#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": # "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

bool search(int n,vi& hist)
{
	if(n==4)
		return true;
	
	rep(i,9){
		if(hist[i]>=3){
			hist[i]-=3;
			if(search(n+1,hist)){
				//printf("%d %d %d\n",i,i,i);
				return true;
			}
			hist[i]+=3;
		}
		else if(i<=6 && hist[i] && hist[i+1] && hist[i+2]){
			rep(j,3)
				hist[i+j]--;
			if(search(n+1,hist)){
				//printf("%d %d %d\n",i,i+1,i+2);
				return true;
			}
			rep(j,3)
				hist[i+j]++;
		}
	}
	return false;
}

bool solve(const vi& a)
{
	vi hist(9);
	rep(i,a.size())
		hist[a[i]]++;
	
	if(*max_element(allof(hist))>=5)
		return false;
	
	rep(i,9){
		if(hist[i]>=2){
			hist[i]-=2;
			if(search(0,hist)){
				//printf("(%d %d)\n",i,i);
				return true;
			}
			hist[i]+=2;
		}
	}
	
	return false;
}

int main()
{
	for(string s;getline(cin,s);){
		vi a(13);
		rep(i,s.size())
			a[i]=s[i]-1-'0';
		
		vi res;
		rep(i,9){
			a.push_back(i);
			if(solve(a))
				res.push_back(i+1);
			a.pop_back();
		}
		
		if(res.size()==0)
			cout<<"0"<<endl;
		else{
			rep(i,res.size())
				cout<<(i==0?"":" ")<<res[i];
			cout<<endl;
		}
	}
	
	return 0;
}