#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector c(N+1,0); vector used(N+1,false); rep(i,N) c[i+1] = __builtin_popcount(i+1); int now = 1, cnt = 0; while(1){ cnt++; if(now == N){ cout << cnt << endl; return 0; } if(now + c[now] <= N){ now += c[now]; }else{ now -= c[now]; if(used[now]){ cout << -1 << endl; return 0; }else{ used[now] = true; } } } }