#include <bits/stdc++.h>
using namespace std;
int n, cnt;
inline int read() {
  int red = 0, f_f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f_f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') red = red * 10 + ch - '0', ch = getchar();
  return red * f_f;
}
int main() {
  n = read();
  if (n & 1)
    printf("%d\n", (n - 1) / 2);
  else {
    cnt = 1;
    while (cnt * 2 <= n) cnt *= 2;
    printf("%d\n", (n - cnt) / 2);
  }
  return 0;
}
