#include <bits/stdc++.h>
using namespace std;
const int Maxn = int(1e6) + 256;
const int INF = int(1e9) + 7;
int main() {
  ios_base ::sync_with_stdio(false);
  int n;
  cin >> n;
  if (n % 2 == 0) {
    int t = 1;
    while (t <= n) {
      t *= 2;
    }
    t /= 2;
    cout << (n - t) / 2 << "\n";
  } else
    cout << (n + 1) / 2 - 1 << "\n";
  return 0;
}
