#include using namespace std; typedef long long ll; const ll INF=1e18; int main(){ int n;cin >> n; vector d(n+1,INF); vector> g(n+1); for(int i=1;i<=n;i++){ int cnt=0; for(int j=0;j<5;j++){ if((i>>j)&1){ cnt++; } } if(i-cnt>=1){ g[i].push_back(i-cnt); } if(i+cnt<=n){ g[i].push_back(i+cnt); } } priority_queue,vector>,greater>> pq; d[1]=1; pq.push({0,1}); while(!pq.empty()){ ll u=pq.top().first,v=pq.top().second; pq.pop(); if(d[v]d[v]+1){ d[x]=d[v]+1; pq.push({d[x],x}); } } } if(d[n]==INF){ cout << -1 << endl; } else{ cout << d[n] << endl; } }