n = list(str(input())) if n[0] == "1" and n[1:] == "3" and len(set(n)) == 2: print(len(n)-1) else: print(-1)