#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000");
using namespace std;
struct Point {
  long long x, y;
};
struct Line {
  long long a, b, c;
};
Line makeLine(Point a, Point b) {
  Line l;
  l.a = b.y - a.y;
  l.b = a.x - b.x;
  l.c = -l.a * a.x - l.b * a.y;
  return l;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void cut(Line l, Point a, Point v, long long& t1, long long& t2) {
  long long A = l.a * v.x + l.b * v.y;
  long long B = -l.c - l.a * a.x - l.b * a.y;
  if (A == 0) {
    if (B > 0) {
      t1 = 1;
      t2 = 0;
      return;
    }
    return;
  }
  if (A > 0) {
    if (B <= 0) return;
    t1 = max(t1, (B + A - 1) / A);
  } else {
    A = -A;
    B = -B;
    if (B < 0) {
      t2 = -1;
      return;
    }
    t2 = min(t2, B / A);
  }
}
int main() {
  int n;
  cin >> n;
  vector<Point> p(n);
  for (int i = 0; i < int(n); ++i) {
    cin >> p[i].x >> p[i].y;
  }
  long long t1 = 0;
  Point v = {p[1].x - p[0].x, p[1].y - p[0].y};
  long long d = gcd(abs(v.x), abs(v.y));
  v.x /= d;
  v.y /= d;
  long long t2 = d;
  for (int i = 1; i <= int(n - 1); ++i) {
    cut(makeLine(p[i], p[(i + 1) % n]), p[0], v, t1, t2);
    if (t1 > t2) break;
  }
  if (t1 > t2) {
    cout << 0 << endl;
  } else {
    cout << t2 - t1 + 1 << endl;
  }
  return 0;
}
