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