#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int pot = 0;
  for (int i = 0; i <= 31; i++) {
    if (n == (1 << i)) {
      cout << 0 << endl;
      return 0;
    }
    if ((1 << i) > n) break;
    pot = i;
  }
  if (n % 2 == 1) {
    cout << (n - 1) / 2 << endl;
    return 0;
  }
  cout << (n - (1 << pot)) / 2 << endl;
}
