def get_bitnum(n): i = 0 while n > 0: if n % 2 == 1: i += 1 n = n // 2 return i def create_route(N): route = [get_bitnum(i+1) for i in range (N)] return route N = int(input()) route = create_route(N) history = [] res = [] def search(pos, time): if pos == N-1: res.append(time) else: history.append(pos) bitnum = route[pos] posR = pos + bitnum posL = pos - bitnum RB = not (posR > N-1 or posR in history) LB = not (posL < 1 or posL in history) if RB and LB: return search(posR, time+1), search(posL, time+1) elif RB and not LB: return search(posR, time+1) elif LB and not RB: return search(posL, time+1) else: pass search(0, 1) if res == []: print(-1) else: print(min(res))