시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB51133.333%

문제

You and your pet red panda live in a one-dimensional world. Your red panda really loves eating apples. There are $N$ boxes (numbered from $1$ to $N$), each containing an apple. Box $i$ is located at point $A_i$. Unfortunately, all the boxes are locked. Luckily, you know the location of all keys; key $i$ that can unlock box $i$ is located at point $B_i$.

Currently, both you and your red panda are at point $S$. You want to gather all the apples and bring them back to point $S$ for your red panda. At any time, you can carry any number of keys and apples.

The distance between two points $p$ and $q$ is $|p - q|$. Determine the minimum total distance you need to cover to bring all the $N$ apples to point $S$.

입력

The first line consists of two integers $N$ $S$ ($1 ≤ N ≤ 100\, 000$; $-10^9 ≤ S ≤ 10^9$).

Each of the next $N$ lines consists of two integers $A_i$ $B_i$ ($-10^9 ≤ A_i , B_i ≤ 10^9$).

출력

Output a single integer representing the minimum total distance you need to cover to bring back all the $N$ apples to point $S$.

예제 입력 1

4 2
7 9
-1 4
7 -7
1 3

예제 출력 1

36

You can bring back all the apples in $36$ seconds by doing the following:

  • Start at point $2$.
  • Go to point $3$ and pick up key $4$.
  • Go to point $4$ and pick up key $2$.
  • Go to point $1$ and open box $4$.
  • Go to point $-1$ and open box $2$.
  • Go to point $-7$ and pick up key $3$.
  • Go to point $9$ and pick up key $1$.
  • Go to point $7$, open boxes $1$ and $3$.
  • Go back to point $2$.

예제 입력 2

1 1
1 1

예제 출력 2

0