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