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