N = input() a = N[0] b = N[1:] ans = False if a =="1": ans = True for i in b: if i != "3": ans = False break if ans: print(len(b)) else: print(-1)