n=input()[::-1] try: t=n.index('1') n=n[:t] if len(set(n)) == 1 and '3' in n: print(len(n)) else: print(-1) except: print(-1)