#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 6;
vector<int> adj[MX];
int dis[MX];
pair<int, int> bfs(int v) {
  memset(dis, -1, sizeof dis);
  dis[v] = 0;
  queue<int> q;
  q.push(v);
  int r = -1, ret = 1;
  while (!q.empty()) {
    int pa = q.front();
    q.pop();
    for (int i = 0; i < adj[pa].size(); i++) {
      int y = adj[pa][i];
      if (dis[y] != -1) continue;
      dis[y] = dis[pa] + 1;
      if (r < dis[y]) {
        r = dis[y];
        ret = y;
      }
      q.push(y);
    }
  }
  return {ret, r};
}
int solve(int x) {
  if (x == 1) return 0;
  return 1 + solve(x / 2);
}
int main() {
  int n;
  cin >> n;
  if (n % 2 == 1)
    cout << n / 2;
  else {
    int rr = solve(n);
    int gg = 1 << rr;
    int ans = (n - gg) / 2;
    cout << ans;
  }
  return 0;
}
