#include <bits/stdc++.h>
int main() {
  int x;
  scanf("%d", &x);
  if (x % 2 == 0) {
    int y = 1;
    while (y <= x) {
      y = y * 2;
    }
    y = y / 2;
    printf("%d", (x - y) / 2);
  } else {
    x = x - 1;
    printf("%d", (x / 2));
  }
  return 0;
}
