N = input() if N[0] != '1' or len(N) == 1: print(-1) else: N = N[1:] M = '3'*len(N) if N == M: print(len(N)) else: print(-1)