/*#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]);
	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; 				
}*/
#include<fstream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	ifstream f1("BOI30.INP");
	ofstream f2("BOI30.OUT");
	string s;
	f1>>s;
	int n=s.length();
	int d[n];
	int i;
	int tong=0;
	int ok=0;
	for(i=0;i<n;i++)
	{
		d[i]=int(s[i]) - 48;
		tong+=d[i];
		if(d[i]==0) ok=1;
	}
	if((tong%3!=0)||(ok==0))
	{
		f2<<-1;
		return 0;
	}
	sort(d,d+n);
	for(i=0;i<n;i++)
	{
		f2<<d[i];
	}
	f1.close();
	f2.close();
	return 0;
}
