N=input() cnt=0 for i in range(1,len(N)): if N[i]=="3" and N[0]=="1": cnt+=1 else: print(-1);exit() print(cnt)