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