#include <bits/stdc++.h>
using namespace std;
long long n, k, t;
int main() {
  cin >> n;
  if (n % 2)
    cout << n / 2;
  else {
    k = n;
    while (k != 1) {
      k /= 2;
      ++t;
    }
    while (t != 0) {
      k *= 2;
      --t;
    }
    t = (n - k) / 2;
    cout << t;
  }
  return 0;
}
