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