import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = read().rstrip() L = len(N) S = b'1' + b'3' * (L-1) answer = L - 1 if N == S else -1 if answer == 0: answer = -1 print(answer)