#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const double Pi = acos(-1.0);
const int Max = 100010;
char str[Max];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n & 1)
      printf("%d\n", ((n + 1) >> 1) - 1);
    else {
      int manx;
      int cnt = n;
      while (n) {
        manx = (n & (-n));
        n -= (n & (-n));
      }
      cnt -= manx;
      printf("%d\n", cnt / 2);
    }
  }
  return 0;
}
