N=input() if len(N)==N.count('3'): print(len(N)) elif N[0]=='1' and N[1:].count('3')==len(N[1:]): print(len(N[1:])) else: print(-1)