a =input() b = a[1:].count("3") print([-1,b][b ==(len(a)-1) and a[0] =="1"])