//pythonで解けないので、解く気はないのですが、問題一覧に表示されるのが面倒なので、尊敬する他の方のコードコピーさせていただきました。

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE 
uint32_t seed, x = 0, y = 1, z = 2, w = 3;
void init(){
  x=seed;y=1;z=2;w=3;
}
uint32_t generate() { 
    uint32_t t = (x^(x<<11));
    x = y;
    y = z;
    z = w;
    w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); 
    return w;
}

const Int N = 10000001;
Int calc(Int k){
  init();
  Int res=0;
  for(Int i=0;i<N;i++)
    res+=generate()<k;
  return res;
};

signed main() {
  cin >> seed;
  Int l=0,r=1e10;
  while(l+1<r){
    Int m=(l+r)>>1;
    if(calc(m)<=N/2) l=m;
    else r=m;
  }
  cout<<l<<endl;
  return 0;
}