from builtins import print global N N = int(input()) L = 1 add = 1 cnt = 1 global List List = [] Reach = 10001 * [False] def dfs(L, addlen, cnt) : if L > N+1 or L < 1 or Reach[L] == True: return Reach[L] = True L += int(addlen) if L == N : List.append(cnt) return dfs(L, str(bin(L).count("1")), cnt + 1) dfs(L, str(bin(L).count("1")) * -1, cnt + 1) dfs(L, add, cnt + 1) try : m = min(List) except ValueError : m = -1 print(m)