N = input() if N[0] != '1': exit(print(-1)) L = len(N) if L != 1: exit(print(-1)) for i in range(1, L): if N[i] != '3': exit(print(-1)) print(L - 1)