n = list(str(input())) for i in range(1,len(n)): if n[0] == "1" and n[i] == "3" and len(set(n)) == 2: print(len(n)-1) break else: print(-1)