#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <climits>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef pair<int, int> pii;

bool calc(string b)
{
	if (b.size() == 0)return true;
	for (char i = '1'; i <= '9'; i++)
	{
		if (count(all(b), i) >= 3)
		{
			string c = b;
			c.erase(c.find(i), 3);
			if (calc(c))return true;
		}
	}
	for (char i = '1'; i <= '9' - 2; i++)
	{
		if (count(all(b), i) && count(all(b), i + 1) && count(all(b), i + 2))
		{
			string c = b;
			c.erase(c.find(i),1);
			c.erase(c.find(i+1),1);
			c.erase(c.find(i+2),1);
			if (calc(c))return true;;
		}
		
	}
	return false;
}

bool check(string a)
{
	for (int i = 1; i <= 9; i++)
	{
		if (count(all(a), '0' + i) > 4)return false;
	}

	for (int i = 1; i <= 9; i++)
	{
		if (count(all(a), '0' + i) >= 2)
		{
			string b = a;
			b.erase(b.find('0' + i, 0),2);
			if (calc(b))return true;
		}
	}
	return false;
}

int main()
{
	string a;
	while (cin >> a)
	{
		vector<int> ans;
		for (int i = 1; i <= 9; i++)
		{
			string b = a;
			b += '0' + i;
			sort(all(b));
			if (check(b))ans.push_back(i);
		}
		if (ans.empty())
		{
			cout << 0 << endl;
		}
		else
		{
			for (int i = 0; i < ans.size(); i++)
			{
				cout << (i == 0 ? "" : " ") << ans[i];
			}
			cout << endl;
		}
	}
}