n=input() ok=n[0]=='1' and not n=='1' for i in range(1,len(n)): ok&=n[i]=='3' print(len(n)-1 if ok else -1)