N = input() if len(N) == 1: print(-1) else: a = N[0] b = N[1:] if a == '1' and b == '3' * (len(N) -1): print(len(N) - 1) else: print(-1)