import Queue n = int(input()) def chkdigit(n): count = 0 if n == 0: return 0 while n: if n%2 == 1: count += 1 n /= 2 return count q = Queue.Queue() q.put([1,0]) isvisited = [0 for i in range(n)] while not q.empty() : tmp = q.get() if tmp[0] == n: print tmp[1] + 1 quit() a = chkdigit(tmp[0]) if 0 < tmp[0] + a < n+1 and isvisited[tmp[0]-1] == 0 : isvisited[tmp[0]-1] = 1 q.put([tmp[0] + a, tmp[1] + 1]) if 0 < tmp[0] -a < n+1 and isvisited[tmp[0]-1] == 0: isvisited[tmp[0]-1] = 1 q.put([tmp[0] - a, tmp[1] + 1]) print -1