#include <bits/stdc++.h>
using namespace std;
long long lowbit(long long x) { return x & (-x); }
long long highbit(long long x) {
  while (x != lowbit(x)) x -= lowbit(x);
  return x;
}
int main() {
  long long n;
  cin >> n;
  if (n & 1)
    cout << n / 2 << endl;
  else
    cout << (n - highbit(n)) / 2 << endl;
  return 0;
}
