#include <iostream>
#include <vector>
#include <queue>
using namespace std;

static const long long INF = 1e9;
int main() {
    int n;
    cin >> n;
    vector<int> v(n+1, INF);
    v[1] = 1;
    queue<int> q;
    q.push(1);

    while(!q.empty()) { 
        int now = q.front(); q.pop();
        int cnt = 0;
        for(int j = 0;1 << j < n;j++) {
            cnt += (now >> j) % 2;
        }
        if(now + cnt <= n && v[now + cnt] == INF) {
            q.push(now + cnt);
            v[now + cnt] = v[now] + 1;
        }
        if(now - cnt > 0 && v[now - cnt] == INF) {
            q.push(now - cnt);
            v[now - cnt] = v[now] + 1;
        }
    }

    if(v[n] == INF)
        cout << -1 << endl;
    else
        cout << v[n] << endl;
}