#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 51;
int n;
inline int read() {
  register int num = 0, neg = 1;
  register char ch = getchar();
  while (!isdigit(ch) && ch != '-') {
    ch = getchar();
  }
  if (ch == '-') {
    neg = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    num = (num << 3) + (num << 1) + (ch - '0');
    ch = getchar();
  }
  return num * neg;
}
int main() {
  n = read();
  printf("%d\n", n & 1 ? n / 2 : (n - (1 << (int)(log2(n)))) / 2);
}
