a=input();print(len(a)-1if len(a)>0and a[0]=='1'and a[1:].count('3')==len(a)-1else-1)