#include <bits/stdc++.h>
long long a, b;
int main() {
  scanf("%d", &a);
  if (a % 2 == 1)
    printf("%d\n", (a - 1) / 2);
  else {
    b = 1;
    while (b * 2 <= a) b *= 2;
    a -= b;
    printf("%d\n", (a + 1) / 2);
  }
}
