#include <bits/stdc++.h>
using namespace std;

#define Name "giaima"

#define FOR(i,l,r) for (int i = l; i <= r; i++)
#define FOD(i,r,l) for (int i = r; i >= l; i--)
#define ll long long
#define ld long double

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	if (fopen(Name".inp", "r")) {
		freopen(Name".inp", "r", stdin);
		freopen(Name".out", "w", stdout);
	}

    string str;
    cin>>str;

    if(accumulate(str.begin(), str.end(), str.size()*-'0')%3!=0){
        cout<<-1;
        return 0;
    }
    sort(str.begin(), str.end(), greater<char>());
    if(str.back()=='0'){
        cout<<str;
    }
    else{
        cout<<-1;
    }
}
