N = input() if N[0] != "1": print(-1) exit() if len(N)==1: print(-1) exit() if N[1] != "3" or len(set(N[1:])) != 1: print(-1) exit() print(len(N)-1)