n = input() if n[0] != "1": print(-1) exit() n = n[1:] ans = 0 for num in n: if num == "3": ans += 1 else: print(-1) exit() print(ans)