#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;

string s;
int c[9];
int ct[9];
vector<int> ans;

bool puzzle(int k){
	bool f;
	rep(i,9){
		if(k==4){
			if(c[i]==2) return true;
		}
		if(i<=6&&c[i]&&c[i+1]&&c[i+2]){
			c[i]--; c[i+1]--; c[i+2]--;
			f = puzzle(k+1);
			c[i]++; c[i+1]++; c[i+2]++;
			if(f) return f;
		}
		if(c[i]>2){
			c[i]-=3;
			f = puzzle(k+1);
			c[i]+=3;
			if(f) return f;
		}
	}
	return false;
}



int main(){
	while(cin>>s){
		rep(i,9){
			ct[i]=0;
		}
		rep(i,13){
			ct[s[i]-'1']++;
		}
		rep(i,9){
			rep(j,9){
				c[j]=ct[j];
			}
			if(c[i]>=4) continue;
			c[i]++;
			if(puzzle(0)) ans.PB(i+1);
		}
		if(ans.empty()) cout<<0<<endl;
		else rep(i,ans.size()) cout<<(i==0?"":" ")<<ans[i];
		cout<<endl;
		memset(ct,0,sizeof(ct));
		ans.clear();
	}
	return 0;
}