x = [int(i) for i in input()] print( len(x)-1 if x[0] == 1 and x.count(3) + 1 == len(x) else -1 )