import re def solve(): N=input() if re.search(r'^13+$', N) is None: return -1 return len(N)-1 print(solve())