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>
struct Point {
  long long int x;
  long long int y;
  std::string pToString() {
    std::string x_s(std::to_string(x));
    std::string y_s(std::to_string(y));
    std::string printP(x_s + " " + y_s);
    return printP;
  }
};
bool operator<(Point const &p1, Point const &p2) {
  if (p1.x == p2.x) {
    return p1.y < p2.y;
  }
  return p1.x < p2.x;
}
Point operator-(Point const &p1, Point const &p2) {
  long long x = p1.x - p2.x;
  long long y = p1.y - p2.y;
  Point temp = {x, y};
  return temp;
}
long long int cross(const Point &t1, const Point &t2, const Point &t3) {
  Point a = t1 - t3;
  Point b = t2 - t3;
  return a.x * b.y - b.x * a.y;
}
long long int getDist(Point const &p1, Point const &p2) {
  Point temp = p1 - p2;
  long long int dist = temp.x * temp.x + temp.y * temp.y;
  return dist;
}
void printStack(std::vector<Point> points) {
  for (Point p : points) {
    std::cout << p.pToString() << std::endl;
  }
}
void adjustPolygon(std::vector<Point> &polygon) {
  auto pointA = polygon[0];
  auto pointB = polygon[1];
  for (int i = 0; i < polygon.size(); i++) {
    polygon[i] = polygon[i] - pointB;
  }
  if (polygon[1].y > polygon[2].y) {
    for (int i = 0; i < polygon.size(); i++) {
      polygon[i].x *= -1;
      polygon[i].y *= -1;
    }
  }
}
long double getIntersect(Point a, Point b) {
  if (a.y == b.y) {
    return 1e9L;
  }
  if (a.y > b.y) {
    std::swap(a, b);
  }
  long double slope = (long double)b.y / (b.y - a.y);
  return b.x + (a.x - b.x) * slope;
}
int getTowers(std::vector<Point> polygon) {
  int numTowers;
  long long int min = 0;
  long long int max = polygon[0].x;
  Point maxBase = polygon[0];
  Point minBase = polygon[1];
  if (polygon.size() < 3) {
    return (max - min) + 1;
  }
  for (int i = 2; i < polygon.size() - 1; i++) {
    long long int crs1 = cross(polygon[i + 1], polygon[i], maxBase);
    long long int crs2 = cross(polygon[i + 1], polygon[i], minBase);
    if (crs1 < 0 && crs2 < 0) {
      return 0;
    }
    long double inter = getIntersect(polygon[i], polygon[i + 1]);
    if (crs1 < 0) {
      max = std::min(max, (long long int)std::floor(inter));
    }
    if (crs2 < 0) {
      min = std::max(min, (long long int)std::ceil(inter));
    }
    if (min > max) {
      return 0;
    }
  }
  numTowers = max - min;
  return numTowers + 1;
}
int main() {
  int numPoints;
  long long int inputX;
  long long int inputY;
  std::vector<Point> polygon;
  int numTowers;
  std::cin >> numPoints;
  for (int i = 0; i < numPoints; i++) {
    std::cin >> inputX >> inputY;
    Point p = {inputX, inputY};
    polygon.emplace_back(p);
  }
  adjustPolygon(polygon);
  numTowers = getTowers(polygon);
  if (numTowers < 0) {
    std::cout << "0" << std::endl;
  } else {
    std::cout << numTowers << std::endl;
  }
  return 0;
}
