#include <bits/stdc++.h>
using namespace std;
int solve(int n) {
  int ans = 1e9 + 5;
  for (int i = 1; i <= n; i <<= 1) {
    if ((n - i) % 2 == 0) {
      ans = min(ans, (n - i) / 2);
    }
  }
  return ans;
}
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    printf("%d\n", solve(n));
  }
  return 0;
}
