#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int INF = (1 << 30) - 1;
const int mod = 1e6 + 3;
const int MAXN = 700010;
int ans[11] = {0, 0, 0, 1, 0, 2, 1, 3, 0, 4, 1};
int main() {
  int n;
  scanf("%d", &n);
  if (n <= 10) {
    printf("%d\n", ans[n]);
    return 0;
  }
  int k = 1;
  while (n > (1 << (k + 1)) - 2) k++;
  while (k) {
    int t = n - (1 << k) + 2;
    if (t % 2 == 0) {
      t /= 2;
      printf("%d\n", t - 1);
      return 0;
    }
    k--;
  }
  int ans = n / 2 - 1;
  if ((ans + 1) * 2 < n) ans++;
  printf("%d\n", ans);
  return 0;
}
