void main() { enum INF = 10 ^^ 9; const N = readInt; auto dist = new int[N + 1]; dist[] = INF; dist[1] = 1; int[] que; que ~= 1; while (!que.empty) { int u = que.front; que.popFront; int x = u + popcnt(u); int y = u - popcnt(u); if (x <= N && chmin(dist[x], dist[u] + 1)) { que ~= x; } if (y >= 1 && chmin(dist[y], dist[u] + 1)) { que ~= y; } } int ans = dist[N]; if (ans == INF) ans = -1; ans.writeln; } import std,core.bitop; string[]_R; string readString(){while(_R.empty){_R=readln.chomp.split;}auto ret=_R.front;_R.popFront;return ret;} int readInt(){return readString.to!int;} long readLong(){return readString.to!long;} ulong readULong(){return readString.to!ulong;} real readReal(){return readString.to!real;} bool chmin(T)(ref T A,T B){if(A>B){A=B;return true;}else{return false;}} bool chmax(T)(ref T A,T B){if(A1){int mid=(L+R)/2;(A[mid]1){int mid=(L+R)/2;(A[mid]<=x?L:R)=mid;}return R;}