#include <bits/stdc++.h>


using namespace std;
ifstream f1("boi30.inp");
ofstream f2("boi30.out");
 
int main()
{string s,x=""; char tg;
int i,tong=0,j;
f1>>s;
for (i=0;i<s.length()-1;i++)
{for (j=i+1;j<s.length();j++)
if (s[i]<s[j])
{ tg=s[i];
s[i]=s[j];
s[j]=tg;
}}
for (i=0;i<s.length();i++)
{ x=x+s[i];
tong=tong+atoi(x.c_str());
x="";
}
if (tong%3==0&&s[s.length()-1]=='0')
 f2<<s;
 else f2<<-1;

    return 0;
}
