#include using namespace std; #define rep(i,n) for (int i = 0; i < n; ++i) using ll = long long; const int INF=1e9; int dp[10001]; int N; void f(int x=2,int y=2){ if(x<=0||x>N||dp[x]<=y)return; dp[x]=y; int z=__builtin_popcount(x); f(x-z,y+1); f(x+z,y+1); } int main() { cin>>N; rep(i,10001)dp[i]=INF; dp[1]=1; f(); cout<<(dp[N]==INF?-1:dp[N])<