N = input() E = '1' X = 0 if N[0] != '1': X = -1 else: for i in range(len(N)): if int(E) == int(N): if i == 0: X = -1 break if i == len(N) - 1: X = -1 break E += '3' X += 1 print(X)