#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int n;
	cin>>n;
	queue<pair<int,int>> q;
	q.push(make_pair(1,1));
	vector<int> vec(11000,0);
	vec.at(1)=1;
	while(!q.empty()){
		int now=q.front().first;
		int num=q.front().second;
		q.pop();
		if(now==n){
			cout<<num<<endl;
			exit(0);
		}
		int a=__builtin_popcount(now);
		if(now+a<=n && vec.at(now+a)==0){
      vec.at(now+a)=1;
			q.push(make_pair(now+a,num+1));
		}
		if(now-a>0 && vec.at(now-a)==0){
      vec.at(now-a)=1;
			q.push(make_pair(now-a,num+1));
		}
		
	}
	cout<<-1<<endl;
}