def bitone(n): cnt = 0 m = n while m > 0: if m % 2 == 1: cnt += 1 m = m / 2 return cnt def sugoroku(n): now = 1 cnt = 1 history = [] flag = False while now < n: b = bitone(now) cnt += b if now + b > n: now -= b else: now += b if now in history: return -1 else: history.append(now) return cnt print sugoroku(int(raw_input()))