#include <bits/stdc++.h>
using namespace std;
const int inf_int = 2e9;
const long long inf_ll = 2e18;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  if (n & 1)
    cout << n / 2 << endl;
  else {
    int pw = 1;
    while (pw * 2 <= n) pw *= 2;
    printf("%d\n", (n - pw) / 2);
  }
  return 0;
}
