import re n = input() pattern = '^13+$' match = re.search(pattern,n) if match: print(len(n)-1) else: print(-1)