#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
int main()
{
	while (true)
	{
		std::string str;
		std::cin >> str;
		if (std::cin.eof())
		{
			break;
		}
		std::istringstream ist(str);
		std::vector<int>num;
		num.reserve(14);
		for (char n; ist >> n;)num.push_back(static_cast<int>(n - '0'));
		std::vector<int>answer;
		answer.reserve(9);
		for (int i = 1; i <= 9; i++)
		{
			bool is_ok = true;
			auto num_copy = num;
			num_copy.push_back(i);
			std::sort(num_copy.begin(), num_copy.end());
			for (int j = 0; j < static_cast<int>(num_copy.size()) - 4; j++)
			{
				if (num_copy[j] == num_copy[j + 4])
				{
					is_ok = false;
					break;
				}
			}
			if (is_ok)
			{
				for (int j = 0; j < num_copy.size() - 1; j++)
				{
					auto num_copy_copy = num_copy;
					if (is_ok = num_copy_copy[j] == num_copy_copy[j + 1])
					{
						num_copy_copy.erase(num_copy_copy.begin() + j, num_copy_copy.begin() + j + 2);
						for (int k = 0; k < num_copy_copy.size() / 3; k++)
						{
							if (num_copy_copy.size() >= 9 && num_copy_copy[0] == num_copy_copy[1] - 1 && num_copy_copy[1] == num_copy_copy[2] && num_copy_copy[2] == num_copy_copy[3] - 1 && num_copy_copy[3] == num_copy_copy[5] && num_copy_copy[5] == num_copy_copy[6] - 1 && num_copy_copy[6] == num_copy_copy[7] && num_copy_copy[7] == num_copy_copy[8] - 1)
							{
								num_copy_copy.erase(num_copy_copy.begin(), num_copy_copy.begin() + 9);
								k = -1;
							}
							else if (num_copy_copy.size() >= 6 && (num_copy_copy[0] == num_copy_copy[1] && num_copy_copy[1] != num_copy_copy[2] && num_copy_copy[2] == num_copy_copy[3] && num_copy_copy[3] != num_copy_copy[4] && num_copy_copy[4] == num_copy_copy[5] || num_copy_copy[0] == num_copy_copy[1] - 1 && num_copy_copy[1] == num_copy_copy[2] && num_copy_copy[3] == num_copy_copy[4] && num_copy_copy[4] == num_copy_copy[5] - 1))
							{
								num_copy_copy.erase(num_copy_copy.begin(), num_copy_copy.begin() + 6);
								k = -1;
							}
							else if (num_copy_copy[0] == num_copy_copy[1] && num_copy_copy[1] == num_copy_copy[2] || num_copy_copy[1] == num_copy_copy[0] + 1 && num_copy_copy[2] == num_copy_copy[0] + 2)
							{
								num_copy_copy.erase(num_copy_copy.begin(), num_copy_copy.begin() + 3);
								k = -1;
							}
							else
							{
								is_ok = false;
								break;
							}
						}
						if (is_ok)
						{
							answer.push_back(i);
							break;
						}
					}
				}
			}
		}
		if (answer.size() == 0)
		{
			std::cout << '0';
		}
		else
		{
			for (int i = 0; i < answer.size(); i++)
			{
				if (i != 0)
				{
					std::cout << ' ';
				}
				std::cout << answer[i];
			}
		}
		std::cout << std::endl;
	}
	return 0;
}
