a = list(input()) b = a.pop(0) c = set(a) if b == '1' and len(c) == 1 and c == {3}: print(len(a)) else: print('-1')