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.
import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start(); 
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");
	
	int pNum;
	
	Point[] ps1;
	Point[] ps2;
	
	Point[] ps;
	Line AB;
	Line[] lines;
	List<Point> lst = new ArrayList<Main.Point>(2000);
	
	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		
		pNum = nextInt();
		ps1 = new Point [pNum];
		ps2 = new Point [pNum];
		
		for (int i = 0; i < pNum; i++) {
			Point p = new Point(nextDouble(), nextDouble());
			Point ip = new Point(p.x, -p.y);
			ps1[i] = p;
			ps2[i] = ip;
		}
		
		if (ps1[0].y > ps1[2].y) {
			ps = ps1;
		} else {
			ps = new Point [pNum];
			ps[0] = ps2[1];
			ps[1] = ps2[0];
			for (int i = 2; i < pNum; i++)
				ps[i] = ps2[pNum - i + 1];
		}
		
		AB = new Line(ps[0], ps[1]);
		
		lines = new Line [pNum];
		for (int i = 0; i < pNum; i++)
			lines[i] = new Line(ps[i], ps[(i + 1) % pNum]);
		
		double left = ps[0].x;
		double right = ps[1].x;
		
		for (int i = 2; i < pNum - 1; i++) {
			int j = (i + 1) % pNum;
			Line IJ = new Line(ps[i], ps[j]);
			
			double calcA = IJ.calc(ps[0]);
			double calcB = IJ.calc(ps[1]);
//			System.out.println(calcA + " " + calcB);
			
			if (abs(calcA) > 1e-11 && abs(calcB) > 1e-11 && calcA < 0.0 && calcB < 0.0) {
				out.println(0);
				out.close();
				return;
			}
			
			Point its = cll(AB, IJ);
			if (its != null) {
				if (abs(calcA) > 1e-11 && calcA < 0.0) {
					left = max(left, its.x);
				}
				
				if (abs(calcB) > 1e-11 && calcB < 0.0) {
					right = min(right, its.x);
				}
			}
		}
		
//		System.out.println(left);
//		System.out.println(right);
		
		int il = (int) (left + 0.5);
		int ir = (int) (right);
		int ans = max(0, ir - il + 1);
		
		out.println(ans);
		
		out.close();
	}
	
	Point cll(Line l1, Line l2) {
		double det = -det(l1.A, l1.B, l2.A, l2.B);
		if (abs(det) < 1e-11)
			return null;
		return new Point(det(l1.C, l1.B, l2.C, l2.B) / det, det(l1.A, l1.C, l2.A, l2.C) / det);
	}

	double det(double a1, double b1, double a2, double b2) {
		return a1 * b2 - a2 * b1;
	}

	class Point implements Comparable<Point> {
		double x;
		double y;
		
		Point(double x, double y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int compareTo(Point p) {
			if (abs(x - p.x) > 1e-12)
				return x < p.x ? -1 : 1;
			return 0;
		}
	}
	
	class Event {
		int type;
		double x;
	}
	
	class Line {
		Point p1;
		Point p2;
		double A;
		double B;
		double C;
		
		Line(Point p1, Point p2) {
			this.p1 = p1;
			this.p2 = p2;
			A = p2.y - p1.y;
			B = p1.x - p2.x;
			C = -(A * p1.x + B * p1.y);
		}

		double calc(Point p) {
			return A * p.x + B * p.y + C;
		}

		boolean contains(Point p) {
			return p1.x + 1e-12 < p.x && p.x < p2.x - 1e-12;
		}
	}
	
	/*************************************************************** 
	 * Input 
	 **************************************************************/
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}
