import re a = input() if re.match(r'^13+$', a) == None: print(-1) else: print(len(a)-1)