#include #include #include using namespace std; int main(){ long long n;cin>>n; if(n == 1){ cout << 2 << endl; return 0; } long long nwi = 2; queue X; while(1){ if(n < (1LL<<(nwi-1)))break; long long nw = 1; long long sm = 0; while(X.size())X.pop(); while(n > nw){ sm += nw; X.push(nw); if(X.size() > nwi){ sm -= X.front(); X.pop(); } nw = sm; } if(nw == n){ cout << nwi << endl; return 0; } nwi++; } cout << -1 << endl; }