#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(int)(b);i++) #define rep(i,n) FOR(i,0,n) #define ZERO(a) memset(a,0,sizeof(a)) bool visited[10010]; int calc(int n) { int res = 0; while(n) { if(n & 1) res++; n >>= 1; } return res; } int main() { ZERO(visited); int n; cin>>n; vector a(10010); rep(i,n+1) a[i] = calc(i); int ans = 0, pos = 1; while(1) { ans++; visited[pos] = 1; if(n == pos) break; pos += (pos+a[pos] <= n ? a[pos] : -a[pos]); if(visited[pos]) { cout << -1 << "\n"; return 0; } } cout << ans << "\n"; return 0; }