def fnc(s): t = list(map(str,range(1,s+1))) pos = 0 count = 1 li = [] while t[pos] != t[-1]: b = bin(int(t[pos])) tmp = str(b).count("1") if pos + tmp > len(t)-1: pos -= tmp else : pos += tmp if t[pos] in li: return -1 count += 1 li.append(t[pos]) return count print(fnc(int(input())))