#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;


bool recur(int it, int p[13], bool f)
{
	while (p[it] == 0 && it < 10)
		it++;

	if (it == 10 && f)
		return true;
	else if (it == 10 && !f)
		return false;


	int a[13];
	int b[13];
	int c[13];
	memcpy(a, p, sizeof(a));
	memcpy(b, p, sizeof(b));
	memcpy(c, p, sizeof(c));

	bool ok = false;
	if (p[it] > 0 && p[it+1] > 0 && p[it+2] > 0)
	{
		--a[it]; --a[it+1]; --a[it+2];
		ok |= recur(it, a, f);
	}
	if (p[it] >= 3)
	{
		b[it] -= 3;
		ok |= recur(it, b, f);
	}
	if (p[it] >= 2 && !f)
	{
		c[it] -= 2;
		ok |= recur(it, c, true);
	}

	return ok;
}

int main()
{
	char buf[128];

	while (fgets(buf, sizeof(buf), stdin))
	{
		buf[13] = '\0';
		int p[13];
		memset(p, 0, sizeof(p));
		for (int i = 0; buf[i] != '\0'; ++i)
			++p[buf[i]-'0'];

		bool any = false;
		vector<int> ans;
		for (int i = 1; i <= 9; ++i)
		{
			int wp[13];
			memcpy(wp, p, sizeof(wp));
			++wp[i];
			bool ok = true;
			for (int j = 1; j <= 9; ++j)
				ok &= wp[j] <= 4;
			if (!ok)
				continue;

			if (recur(1, wp, false))
			{
				ans.push_back(i);
			}
		}
		if (ans.size())
		{
			for (int i = 0; i < ans.size()-1; ++i)
				printf("%d ", ans[i]);
			printf("%d\n", ans[ans.size()-1]);
		}
		else
			printf("0\n");
	}

	return 0;
}