n = input()


if "0" in n and int(n) % 3 == 0:
    n = sorted([i for i in n], reverse=True)
    print("".join(n))
else:
    print(-1)
cfcf2cbbdc8bb9d2c602b349d7cb9f1354771f1d
<mask token>

<mask token>
if '0' in n and int(n) % 3 == 0:
    n = sorted([i for i in n], reverse=True)
    print(''.join(n))
else:
    print(-1)

n = input()
if '0' in n and int(n) % 3 == 0:
    n = sorted([i for i in n], reverse=True)
    print(''.join(n))
else:
    print(-1)

n = input()


if "0" in n and int(n) % 3 == 0:
    n = sorted([i for i in n], reverse=True)
    print("".join(n))
else:
    print(-1)