N = input() if N.replace("1","").replace("3","") == "": print(N.count("3")) else: print(-1)