#include<bits/stdc++.h>
using namespace std;
long long m;
int n;
void r(vector <int> &s)
{
    s.clear();
    char a;
    a=getchar();
    while (a>='0'&&a<='9')
    {
        s.push_back(a-'0');
        a=getchar();
    }
}
bool check(char a)
{
    return a>='0'&&a<='9';
}
string a;vector <int> s;
bool lf (int a,int b)
{
    return a>b;
}
void w(int x)
{
    while (x>9) w(x/10);
    putchar(x%10+'0');
}
int main()
{
    freopen("BOI30.inp","r",stdin);
    freopen("BOI30.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tong=0;
    r(s);
    for (int i=0;i<s.size();i++)
    {
        tong=tong+s[i];
    }
    if (tong%3!=0) {
            putchar('-');putchar('1');
            return 0;
    }
    sort(s.begin(),s.end());
    if (s[0]!=0)
    {
        putchar('-');
        putchar('1');
        return 0;
    }
    for (int i=s.size()-1;i>=0;i--)
    {
        putchar(s[i]+'0');
    }
  /*  cin>>a;
    for (int i=0;i<a.size();i++)
    {
        s.push_back(a[i]-'0');
    }
    for (int i=0;i<s.size();i++)
    {
        tong = tong + s[i];
    }
    if (tong % 3 != 0)
    {
        cout<<-1;
        return 0;
    }
    sort (s.begin(),s.end());
    if (s[0]!=0)
    {
        cout<<-1;
        return 0;
    }
    for (int i=s.size()-1;i>=0;i++)
    {
        cout<<s[i];
    } */
}
