n=input() a,b=n.count("1"),n.count("3") if a+b!=len(n) or a==0 or a>1 or b==0 or n[0]!='1': print("-1") else: print(b)