#include <bits/stdc++.h>
namespace TNT {
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
inline int qpow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = ans * x;
    x = x * x;
    y >>= 1;
  }
  return ans;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void main() {
  int n = read();
  if (n % 2)
    write((n - 1) / 2), putchar('\n');
  else {
    int pos;
    n >>= 1;
    for (register int i = 28; i >= 0; i--)
      if (n >> i) {
        n -= qpow(2, i);
        break;
      }
    write(n), putchar('\n');
  }
  return;
}
}  // namespace TNT
int main() {
  TNT::main();
  return 0;
}
