Package for this problem was not updated by the problem writer or Codeforces administration after we’ve upgraded the judging servers. To adjust the time limit constraint, solution execution time will be multiplied by 2. For example, if your solution works for 400 ms on judging servers, then value 800 ms will be displayed and used to determine the verdict.

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
B. Young Photographer

time limit per test

2 secondsmemory limit per test

64 megabytesinput

standard inputoutput

standard outputAmong other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*_{0} of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*_{1} to position *b*_{1}, the second — from *a*_{2} to *b*_{2}

What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.

Input

The first line of the input file contains integers *n* and *x*_{0} (1 ≤ *n* ≤ 100; 0 ≤ *x*_{0} ≤ 1000). The following *n* lines contain pairs of integers *a*_{i}, *b*_{i} (0 ≤ *a*_{i}, *b*_{i} ≤ 1000; *a*_{i} ≠ *b*_{i}).

Output

Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.

Examples

Input

3 3

0 7

14 2

4 6

Output

1

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/13/2021 16:06:47 (i1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|