#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define INF 1000000000

int numOfBits(int bits)
{
	int res = 0; int key = 1;
	while (key <= bits)
	{
		if (bits & key)
			++res;
		key = key << 1;
	}

	return res;
}

int main()
{
	int N;
	cin >> N;
	
	vector<int> dis;
	dis.assign(N + 1, INF);
	queue<int> q;
	dis[1] = 1;
	q.push(1);
	while (q.size())
	{
		int key = q.front(); q.pop();
		if (key == N)
			break;
		if (1 <= key - numOfBits(key) && key - numOfBits(key) <= N && dis[key - numOfBits(key)] == INF)
		{
			dis[key - numOfBits(key)] = dis[key] + 1;
			q.push(key - numOfBits(key));
		}
		if (1 <= key + numOfBits(key) && key + numOfBits(key) <= N && dis[key + numOfBits(key)] == INF)
		{
			dis[key + numOfBits(key)] = dis[key] + 1;
			q.push(key + numOfBits(key));
		}
	}

	cout << (dis[N] != INF ? dis[N] : -1) << endl;

	return 0;
}