n = list(input()) if len(n) == 1: print(-1) exit() elif n[0]=="1": for i in range(1,len(n)): if n[i]!="3": print(-1) exit() print(len(n)-1) else: print(-1)