#include using namespace std; int main() { int n, lane, bit, mov; int through[10050]; bool check[10000]; bool flg, hit; cin >> n; flg=true; hit=false; through[0]=1; check[0]=true; for( int i=1; i>=1 )bit+=j&1; lane=(i-bit)*(0==i); mov=through[i]+1*(0==i); check[i]=false; through[lane]*=(through[lane]<=mov); flg=(0==through[lane]); while( n-1>lane && 0==through[lane] ) { through[lane]=mov; bit=1; for( int j=lane+1; 1>=1 )bit+=j&1; lane+=bit; mov++; through[lane]*=(through[lane]<=mov); } if(n-1==lane) { hit=true; through[n-1]=mov; } } } if(hit)flg=false; } if(!hit)mov=-1; cout << mov << endl; return 0; }