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