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