import sys s=list(input()) if not s[0]==1: print(-1) else: for i in range(1,len(s)): if not s[i]==3: print(-1) sys.exit() print((len(s)-1))