#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	queue<int>q;
	vector<int>dp(n + 1, 1e9);
	dp[1] = 1;
	q.push(1);
	while (!q.empty()) {
		int nxt = q.front();
		q.pop();
		int b = __builtin_popcount(nxt);
		if (nxt - b >= 1 && dp[nxt - b] > 1 + dp[nxt]) {
			dp[nxt - b] = 1 + dp[nxt];
			q.push(nxt - b);
		}
		if (nxt + b <= n && dp[nxt + b] > 1 + dp[nxt]) {
			dp[nxt + b] = 1 + dp[nxt];
			q.push(b + nxt);
		}
	}
	int ans = 0;
	if (dp[n] == 1e9)ans = -1;
	else ans = dp[n];
	cout << ans << endl;
}