import sys readline=sys.stdin.readline N=readline().rstrip() ans=len(N)-1 if N!="1"+"3"*ans or ans==0: ans=-1 print(ans)