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