#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

struct edge{ int to,cost; };
const int N = 2e5+10;
vector< edge > G[N];

int n;
void dikstra(int s){
  typedef pair<int, int> P;
  const int INF = 1 << 30;

  priority_queue<P,vector<P>,greater<P>> que;
  vector<int> d(N,INF); //sからの最短距離
  d[s] = 0;
  que.push({0,s}); //{最短距離,頂点}

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push( {d[e.to],e.to} );
      }
    }
  }
  if(d[n] == INF) cout << -1 << endl;
  else cout << d[n]+1 << endl;
}

signed main(){

  cin >> n;
  for(int i = 1; i <= n; i++){
    int cost = __builtin_popcount(i);
    G[i].push_back({i + cost,1});
    G[i].push_back({i - cost,1});
  }

  dikstra(1);

  return 0;
}