#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  if (n & 1)
    cout << n / 2 << '\n';
  else {
    long long b = 1;
    while (b * 2 <= n) b <<= 1;
    cout << (n - b) / 2 << '\n';
  }
  return 0;
}
