#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <map>
#include <numeric>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int hai[9];

bool search()
{
	if(accumulate(hai, hai+9, 0)==2 && *max_element(hai, hai+9)==2)
		return true;

	rep(i, 9){
		if(!hai[i]) continue;
		bool res = false;
		if(hai[i]>=3){
			hai[i] -= 3;
			res = search();
			hai[i] += 3;
		}
		if(i<7 && hai[i] && hai[i+1] && hai[i+2]){
			hai[i]--;
			hai[i+1]--;
			hai[i+2]--;
			res = search();
			hai[i]++;
			hai[i+1]++;
			hai[i+2]++;
		}
		if(res) return true;
	}
	return false;
}

int main()
{
	while(1){
		fill(hai, hai+10, 0);
		char c;
		rep(i, 13){
			if(scanf(" %c", &c) == EOF)
				return 0;
			hai[c-'1']++;
		}
		vi ans;
		rep(i, 9){
			if(hai[i]>=4) continue;

			hai[i]++;
			if(search())
				ans.push_back(i+1);
			hai[i]--;
		}

		if(ans.empty())
			puts("0");
		else{
			rep(i, ans.size()){
				printf("%d", ans[i]);
				if(i<(int)ans.size()-1)
					printf(" ");
			}
			puts("");
		}
	}

	return 0;
}