#include<bits/stdc++.h>
using namespace std;
int main ()
{
	ifstream f1("BOI30.INP");
	ofstream f2("BOI30.OUT");
	string s;
	char tg;
	getline(f1,s);

	int a,b,c,tong=0;
	for(a=0;a<s.length();a++)
		tong=tong+int(s[a])-48;
	if(tong%3!=0) f2<<-1;
	if(tong%3==0)
	{
	for(a=s.length()-1;a>0;a--)
		for(b=a-1;b>=0;b--)
			{
				if(s[a]>s[b])
					{
						tg=s[a];
						s[a]=s[b];
						s[b]=tg;
					}
			}
	}
	
	if (s[s.length()-1]=='0') f2<<s; else f2<<-1; 				
}
