#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int M = 1e5 + 10;
int n;
int main() {
  while (~scanf("%d", &n)) {
    int m;
    if (n & 1)
      m = n / 2;
    else {
      m = 2;
      while (m <= n) m <<= 1;
      m /= 2;
      m = (n - m) / 2;
    }
    printf("%d\n", m);
  }
  return 0;
}
