\begin{array}{c} \color{#db1616}{\texttt{#Khoadang09}} \end{array}
var s : string;
function int_(c:char):integer;
var tg : integer;
begin
val(c,tg);
exit(tg);
end ;
function len(s:string):integer;
begin
exit(length(s));
end ;
function check(s:string):string;
begin
if len(s) <> 0 then exit(s);
exit('-1');
end ;
begin
readln(s);
while true do
begin
if int_(s[1]) mod 3 = 0 then delete(s,1,1)
else if int_(s[len(s)]) mod 3 = 0 then delete(s,len(s),1)
else if (int_(s[1]) + int_(s[len(s)])) mod 3 = 0 then
begin
delete(s,1,1);
delete(s,len(s),1);
end
else break;
if len(s) = 0 then break;
end ;
write(check(s));
end .