"""
    @ Baek 10610. 30
    @ Prob. https://www.acmicpc.net/problem/10610
     Ref.   
    @ Algo: Greedy
    @ Start day: 20. 08. 26.
    @ End day: 20. 08. 26.
"""



N = [int(i) for i in input()]
N.sort(reverse=True)
if N[-1] == 0 and sum(N) % 3 == 0:
    print("".join(map(str, N)))
else:
    print(-1)


"""
102
>
210
"""


742fe6d0eb993cf2d849123397b92e8ace29b934
<mask token>

<mask token>
N.sort(reverse=True)
if N[-1] == 0 and sum(N) % 3 == 0:
    print(''.join(map(str, N)))
else:
    print(-1)
<mask token>

<mask token>
N = [int(i) for i in input()]
N.sort(reverse=True)
if N[-1] == 0 and sum(N) % 3 == 0:
    print(''.join(map(str, N)))
else:
    print(-1)
<mask token>

"""
    @ Baek 10610. 30
    @ Prob. https://www.acmicpc.net/problem/10610
     Ref.   
    @ Algo: Greedy
    @ Start day: 20. 08. 26.
    @ End day: 20. 08. 26.
"""



N = [int(i) for i in input()]
N.sort(reverse=True)
if N[-1] == 0 and sum(N) % 3 == 0:
    print("".join(map(str, N)))
else:
    print(-1)


"""
102
>
210
"""

