n = input() l = [int(x) for x in list(str(n))] counter = 0 if l[0] == 1: l.pop(0) for i in range(len(l)): if l[i] == 3: counter += 1 else: counter = 0 break if counter > 0: print(counter) else: print(-1)