#include <bits/stdc++.h>
using namespace std;
bool prime_check(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
signed main() {
  long long n;
  cin >> n;
  long long ar[1000001];
  for (long long i = 0; i <= 1000000; i++) {
    ar[i] = 1;
  }
  ar[0] = ar[1] = 0;
  for (long long i = 2; i * i <= 1000000; i++) {
    if (ar[i]) {
      for (long long j = 2; j * i <= 1000000; j++) {
        ar[i * j] = 0;
      }
    }
  }
  if (prime_check(n) == true) {
    cout << '1' << endl;
    return 0;
  } else if (n % 2 == 0) {
    cout << n / 2 << endl;
  } else {
    for (long long i = 3; i * i <= n; i++) {
      if (ar[i] && n % i == 0) {
        n -= i;
        break;
      }
    }
    cout << (n / 2) + 1 << endl;
  }
}
