#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    if (n & 1)
      printf("%d\n", ((n + 1) >> 1) - 1);
    else {
      int cnt;
      int h = 1;
      while (h * 2 <= n) {
        h *= 2;
      }
      printf("%d\n", (n - h) / 2);
    }
  }
  return 0;
}
