x = input() def a(): if x == '1': return -1 if x[0] != '1': return -1 for i in range(1, len(x)): if x[i] != '3': return -1 return len(x)-1 print(a())