#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
int T, n, s, ans;
int main() {
  T = 1;
  while (T--) {
    cin >> n;
    s = 0;
    if (s == 1) {
      ans = (n + 1) / 2;
      cout << ans << endl;
      continue;
    }
    ans = (n + 1) / 2;
    for (long long j = (30); j >= (0); j--) {
      if (n >= (1 << j)) {
        int rest = n - (1 << j);
        if ((!(rest & 1))) ans = (ans < rest / 2 ? ans : rest / 2);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
