#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define aLL(g) (g).begin(),(g).end() #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define F(i,j,k) fill(i[0],i[0]+j*j,k) #define P(p) cout<<(p)< vi; typedef vector vl; typedef vector vd; typedef pair pii; typedef pair pll; typedef long long ll; int dx[] = {0,1,0,-1}; int dy[] = {-1,0,1,0}; int sttoi(std::string str){int ret;std::stringstream ss;ss << str;ss >> ret;return ret;} int n; int mini = 10000000; bool field[10001]; int main(){ cin >> n; int pos = 1; int step = 1; queue > q; q.push(make_pair(1,1)); while(!q.empty()){ int pos = q.front().first; int step = q.front().second; q.pop(); if(pos == n){ cout << step << endl; return 0; } int count = 0; int num = pos; for(;num > 0;num = num/2){ if(num%2==1)count++; } if(pos+count < n+1 && !field[pos+count]){ field[pos+count] = true; q.push(make_pair(pos+count,step+1)); } if(pos-count >= 1 && !field[pos-count]){ field[pos-count] = true; q.push(make_pair(pos-count,step+1)); } } cout << -1 << endl; }