#include <bits/stdc++.h>
int F(int n) {
  if (__builtin_popcount(n) == 1) return 0;
  long long i, j, res = 0;
  for (i = 0;; i++) {
    if ((1LL << i) > n) {
      i--;
      return n - ((1LL) << i);
    }
  }
  return 0;
}
int main() {
  int n, res;
  while (scanf("%d", &n) != EOF) {
    res = 0;
    if (n & 1)
      res = n >> 1;
    else
      res = F(n >> 1);
    printf("%d\n", res);
  }
  return 0;
}
