n = input() if n[0]=="1" and sum([1 for i in range(1,len(n)) if n[i]!="3"])==0 and len(n)!=1: print(len(n)-1) else: print(-1)