#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
freopen("BAI07.INP","r",stdin);
freopen("BAI07.OUT","w",stdout);
string n;
cin >> n;
int l = n.length();
sort(n.begin(),n.end(),greater<char>());
if (n[l-1] == '0')
{
int t = 0;
for (int i = 0;i < l;i++)
t += n[i] - 48;
if (t % 3 == 0)
cout << n;
else
cout << -1;
}
else
cout << -1;
}