#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int inf = 1000000009;
int i, j, k, m, n, l;
int ans;
int f(int n, int m) {
  return n < m ? (n + (n % 2) * (m - 1)) / 2 : f(n - m, 2 * m);
}
int main() {
  cin >> n;
  cout << (n < 2 ? 0 : f(n - 2, 2)) << endl;
  return 0;
}
