//#include<bits/stdc++.h>
//#include<windows.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
bool cmp(char a,char b){
return a>b;
}
int main(){
char str[10001]={};
cin>>str;
bool f=false;
int n=0;
for(int i=0;i<strlen(str);i++){
if(str[i]=='0') f=true;
n+=str[i]-'0';
}if(n%3==0 && f){
sort(str,str+strlen(str),cmp);
cout<<str;
}else{
cout<<-1;
}
return 0;
}