#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  if (n % 2 == 1) {
    cout << n / 2 << endl;
    return 0;
  }
  n /= 2;
  int p = 1;
  while (p <= n) p *= 2;
  p /= 2;
  cout << n - p << endl;
  return 0;
}
