#include <fstream>
#include <string>
#include <algorithm>

using namespace std;

ifstream input("BOI30.inp");
ofstream output("BOI30.out");
string a;
int total = 0;

bool comp(int a, int b)
{
	return b < a;
}

int main()
{
	getline(input, a);
	sort(a.begin(), a.end(), comp);
	if (a.back() == '0')
	{
		for (int i = 0; i < a.size(); ++i)
		{
			if (a[i] != '0')
			{
				total += a[i] - '0';
			}
			else
			{
				break;
			}
		}
		if (total % 3 == 0)
		{
			output << a;
		}
		else
		{
			output << -1;
		}
	}
	else
	{
		output << -1;
	}
	input.close();
	output.close();
	return 0;
}