#include <bits/stdc++.h>
using namespace std;
void read(int a = 0) {
  freopen("in", "r", stdin);
  if (a) freopen("out", "w", stdout);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n;
  cin >> n;
  if (n & 1)
    cout << (n - 1) / 2;
  else {
    long long x = 1;
    while (2 * x <= n) x *= 2;
    cout << (n - x) / 2;
  }
}
