In the town of Aalam-Aara (meaning the Light of the Earth), previously there was no crime, no criminals but as the time progressed, sins started creeping into the hearts of once righteous people. Seeking solution to the problem, some of the elders found that as long as the corrupted part of population was kept away from the uncorrupted part, the crimes could be stopped. So, they are trying to set up a compound where they can keep the corrupted people. To ensure that the criminals don't escape the compound, a watchtower needs to be set up, so that they can be watched.

Since the people of Aalam-Aara aren't very rich, they met up with a merchant from some rich town who agreed to sell them a land-plot which has already a straight line fence AB along which a few points are set up where they can put up a watchtower. Your task is to help them find out the number of points on that fence where the tower can be put up, so that all the criminals can be watched from there. Only one watchtower can be set up. A criminal is watchable from the watchtower if the line of visibility from the watchtower to him doesn't cross the plot-edges at any point between him and the tower i.e. as shown in figure 1 below, points X, Y, C and A are visible from point B but the points E and D are not.

<image> Figure 1  <image> Figure 2 

Assume that the land plot is in the shape of a polygon and coordinate axes have been setup such that the fence AB is parallel to x-axis and the points where the watchtower can be set up are the integer points on the line. For example, in given figure 2, watchtower can be setup on any of five integer points on AB i.e. (4, 8), (5, 8), (6, 8), (7, 8) or (8, 8). You can assume that no three consecutive points are collinear and all the corner points other than A and B, lie towards same side of fence AB. The given polygon doesn't contain self-intersections.

Input

The first line of the test case will consist of the number of vertices n (3 ≤ n ≤ 1000).

Next n lines will contain the coordinates of the vertices in the clockwise order of the polygon. On the i-th line are integers xi and yi (0 ≤ xi, yi ≤ 106) separated by a space.

The endpoints of the fence AB are the first two points, (x1, y1) and (x2, y2).

Output

Output consists of a single line containing the number of points where the watchtower can be set up.

Examples

Input

5
4 8
8 8
9 4
4 0
0 4


Output

5


Input

5
4 8
5 8
5 4
7 4
2 2


Output

0

Note

Figure 2 shows the first test case. All the points in the figure are watchable from any point on fence AB. Since, AB has 5 integer coordinates, so answer is 5.

For case two, fence CD and DE are not completely visible, thus answer is 0.
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
struct pos {
  double x, y;
};
struct vec {
  double x, y;
};
struct seg {
  pos a, b;
};
long long sign(double x) { return x < -eps ? -1 : x > eps ? 1 : 0; }
double dot(vec a, vec b) { return a.x * b.x + a.y * b.y; }
double cross(vec a, vec b) { return a.x * b.y - a.y * b.x; }
vec fwd(pos a, pos b) { return {b.x - a.x, b.y - a.y}; }
void mkang(pos src, pos A, pos B) {}
pos operator+(pos p, vec v) { return {p.x + v.x, p.y + v.y}; }
vec operator*(vec v, double t) { return {v.x * t, v.y * t}; }
bool checkInt(seg a, seg b) {
  return sign(cross(fwd(a.a, a.b), fwd(b.a, b.b))) != 0;
}
void prt(pos p) { cout << "p(" << p.x << "," << p.y << ") "; }
void prt(vec p) { cout << "v(" << p.x << "," << p.y << ") "; }
pos segIntSeg(seg a, seg b) {
  double t =
      cross(fwd(a.a, b.a), fwd(a.a, a.b)) / cross(fwd(a.a, a.b), fwd(b.a, b.b));
  return b.a + fwd(b.a, b.b) * t;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n;
  cin >> n;
  vector<pos> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i].x >> v[i].y;
  seg ln = {v[0], v[1]};
  bool inv = v[0].x > v[1].x;
  double L = !inv ? v[0].x : v[1].x, R = !inv ? v[1].x : v[0].x;
  for (long long i = 2; i < n; i++) {
    for (long long j = 2; j < i; j++) {
      seg ln2 = {v[i], v[j]};
      if (!checkInt(ln, ln2)) {
        if ((v[j].x < v[i].x) ^ inv) R = L - 1;
        continue;
      }
      pos p = segIntSeg(ln, ln2);
      if (sign(dot(fwd(v[i], v[j]), fwd(v[i], p))) < 0) continue;
      if (!inv)
        R = min(R, p.x);
      else
        L = max(L, p.x);
    }
    for (long long j = i + 1; j < n; j++) {
      seg ln2 = {v[i], v[j]};
      if (!checkInt(ln, ln2)) {
        if ((v[j].x > v[i].x) ^ inv) L = R + 1;
        continue;
      }
      pos p = segIntSeg(ln, ln2);
      if (sign(dot(fwd(v[i], v[j]), fwd(v[i], p))) < 0) continue;
      if (!inv)
        L = max(L, p.x);
      else
        R = min(R, p.x);
    }
  }
  long long cnt = floor(R) - ceil(L) + 1;
  cout << max(cnt, 0LL) << '\n';
}
