#include #include #include #include #define ll long long using namespace std; int moving[10001]; int check[10001]; void setup(){ for(int i=0;i<=10000;++i){ int j=i; check[i]=10001; while(j){ if(j%2) moving[i]++; j/=2; } } } int main(){ setup(); int n; cin>>n; check[1]=1; int po=1; for(int i=1;i<=n;++i){ if(i+moving[i]<=n) check[i+moving[i]]=min(check[i+moving[i]],check[i]+1); if(i-moving[i]>=1) check[i-moving[i]]=min(check[i-moving[i]],check[i]+1); } for(int i=1;i<=n;++i){ if(i+moving[i]<=n) check[i+moving[i]]=min(check[i+moving[i]],check[i]+1); if(i-moving[i]>=1) check[i-moving[i]]=min(check[i-moving[i]],check[i]+1); } for(int i=1;i<=n;++i){ if(i+moving[i]<=n) check[i+moving[i]]=min(check[i+moving[i]],check[i]+1); if(i-moving[i]>=1) check[i-moving[i]]=min(check[i-moving[i]],check[i]+1); } for(int i=1;i<=n;++i){ if(i+moving[i]<=n) check[i+moving[i]]=min(check[i+moving[i]],check[i]+1); if(i-moving[i]>=1) check[i-moving[i]]=min(check[i-moving[i]],check[i]+1); } for(int i=1;i<=n;++i){ if(i+moving[i]<=n) check[i+moving[i]]=min(check[i+moving[i]],check[i]+1); if(i-moving[i]>=1) check[i-moving[i]]=min(check[i-moving[i]],check[i]+1); } for(int i=1;i<=n;++i){ if(i+moving[i]<=n) check[i+moving[i]]=min(check[i+moving[i]],check[i]+1); if(i-moving[i]>=1) check[i-moving[i]]=min(check[i-moving[i]],check[i]+1); } for(int i=1;i<=n;++i){ if(i+moving[i]<=n) check[i+moving[i]]=min(check[i+moving[i]],check[i]+1); if(i-moving[i]>=1) check[i-moving[i]]=min(check[i-moving[i]],check[i]+1); } for(int i=1;i<=n;++i){ if(i+moving[i]<=n) check[i+moving[i]]=min(check[i+moving[i]],check[i]+1); if(i-moving[i]>=1) check[i-moving[i]]=min(check[i-moving[i]],check[i]+1); } for(int i=1;i<=n;++i){ if(i+moving[i]<=n) check[i+moving[i]]=min(check[i+moving[i]],check[i]+1); if(i-moving[i]>=1) check[i-moving[i]]=min(check[i-moving[i]],check[i]+1); } if(check[n]==10001) cout<<-1<