#include <bits/stdc++.h>
using namespace std;
string toBin(long long int a) { return bitset<64>(a).to_string(); }
void printArr(int *a, int n) {
  for (int i = 0; i < n; i++) printf("%d ", a[i]);
  printf("\n");
}
string intToString(long long int a) {
  ostringstream temp;
  temp << a;
  return temp.str();
}
long long int pow(long long int base, long long int exponent) {
  long long int result = 1;
  while (exponent > 0) {
    if (exponent % 2 == 1) result *= base;
    exponent = exponent >> 1;
    base *= base;
  }
  return result;
}
long long int powerWithMod(long long int base, long long int exponent,
                           long long int modulus) {
  long long int result = 1;
  base %= modulus;
  while (exponent > 0) {
    if (exponent % 2 == 1) result = (result * base) % modulus;
    exponent = exponent >> 1;
    base = (base * base) % modulus;
  }
  return result;
}
bool isPrime(int n) {
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  int limit = ceil(sqrt(n)) + 1;
  for (int d = 3; d <= limit; d += 2) {
    if (n % d == 0) return false;
  }
  return true;
}
int gc(string a, string b) {
  int i = 0, j = 0;
  for (i = 0; i < a.size(); i++) {
    if (a[i] == b[j] && j == b.size() - 1) return i;
    if (a[i] == b[j]) j++;
  }
  return -1;
}
long long int gcdExtended(long long int a, long long int b, long long int *x,
                          long long int *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long int x1, y1;
  long long int gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long int modInverse(long long int a, long long int m) {
  long long int x, y;
  long long int g = gcdExtended(a, m, &x, &y);
  long long int res = (x % m + m) % m;
  return res;
}
int largestPowerOf2(int n) { return (int)pow(2, floor(log(n) / log(2))); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  long long int M = largestPowerOf2(n);
  while ((2 * ((n - M) / 2)) + M < n) M >>= 1;
  cout << ((n - M) / 2) << "\n";
  return 0;
}
