import sys def popcnt(n): return len(list(filter(lambda c: c == '1', list(str(bin(n)))))) def mov(e, p = 1, t = []): if p in t or p > e or p < 1: return -1 q = popcnt(p) t.append(p) if p == e: return len(t) r = list(filter(lambda i: i >= 0, [mov(e, p + q, t), mov(e, p - q, t)])) if len(r) > 0: return min(r) else: return -1 print(mov(int(input())))