n = input() if len(n) == 1 or n[0] != "1": print(-1) else: ans = 0 for i in range(1,len(n)): if n[i] == "3": ans += 1 else: print(-1) exit() print(ans)