#include <bits/stdc++.h>
using namespace std;
int n, type;
inline int read() {
  int s = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    ;
  for (; isdigit(c); c = getchar()) s = s * 10 + c - '0';
  return s;
}
inline void Ans(int n) {
  if (n & 1) return printf("%d\n", n >> 1), void();
  for (int i = 30; i >= 0; --i)
    if ((1 << i) & n) {
      printf("%d\n", (n ^ (1 << i)) / 2);
      return void();
    }
}
signed main(void) {
  n = read();
  Ans(n);
  return 0;
}
