#include <bits/stdc++.h>
using namespace std;
long long n;
int main() {
  cin >> n;
  vector<long long> left, right;
  vector<long long> vx(n), vy(n);
  for (long long i = 0; i < ((long long)n); i++) cin >> vx[i] >> vy[i];
  for (long long i = 0; i < ((long long)n); i++) {
    long long next = (i + 1) % n;
    if (vy[i] == vy[next]) {
      if ((vx[1] - vx[0]) * (vx[next] - vx[i]) < 0 || i == 0) continue;
      cout << "0" << endl;
      return 0;
    }
    long long dx = vx[i] - vx[next];
    long long dy = vy[i] - vy[next];
    long long c = -(dx * vy[i] - dy * vx[i]);
    long long sum = vy[0] * dx + c;
    long long x = sum / dy;
    if (sum % dy) {
      if (vy[i] < vy[next])
        x = (long long)ceil((double)sum / (double)dy);
      else
        x = (long long)floor((double)sum / (double)dy);
    }
    if (vy[i] < vy[next])
      left.push_back(x);
    else
      right.push_back(x);
  }
  left.push_back(min(vx[0], vx[1]));
  right.push_back(max(vx[0], vx[1]));
  long long r = *min_element(right.begin(), right.end());
  long long l = *max_element(left.begin(), left.end());
  cout << max(0ll, r - l + 1) << endl;
}
