#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
long long n;
int main() {
  scanf("%lld", &n);
  if (n % 2 != 0)
    printf("%d\n", n / 2);
  else {
    int m = 2;
    while (m < n) m *= 2;
    if (m > n) m /= 2;
    printf("%d\n", (n - m) / 2);
  }
  return 0;
}
