#include <bits/stdc++.h>
using namespace std;
int x[510000];
int main() {
  int n;
  while (cin >> n) {
    if (n % 2)
      cout << (n >> 1) << endl;
    else {
      int m = 2;
      while (m <= n) {
        m *= 2;
      }
      m /= 2;
      cout << ((n - m) >> 1) << endl;
    }
  }
  return 0;
}
