Frog Jump
문제
A frog is living in a beautiful lake. On the lake, there are a lot of lotus leaves floating in a row, which are represented by closed intervals on the line. The frog likes to be on lotus leaves and moves between them.
The closed intervals, representing lotus leaves, on the line, that is, on the -axis are given and the frog is initially on some interval . The frog can move from an interval to an interval if they overlap. Two intervals overlap if they share a common point. So the frog can move through overlapping intervals. When the frog is moving to the right (left) through the overlapping intervals, it may reach an interval , where it can no longer move to the right (left) from the right (left) endpoint of . In this case, the frog can jump to the interval with the smallest (largest) left (right) endpoint among intervals whose left (right) endpoint is greater (smaller) than the right (left) endpoint of if they exist. Then, the jump length is defined to be the length between the right (left) endpoint of and the left (right) endpoint of . See Figure F.1.
Figure F.1 Jump length
A sequence of intervals is given and the frog should visit the intervals in order from the initial interval . In this travel, the frog has to jump if necessary.
For example, in Figure F.2, eight intervals , , , , , , and are given and numbered from and . The frog is initially on interval . Intervals which the frog should visit in a sequence are given. Then the frog moves from interval to with no jump, and it moves from to with two jumps, say, 3 → 4 and 6 → 7 whose jump length is totally. In this movement, the frog passes through the interval . Nevertheless, it should visit the interval after the interval . Then, there are two jumps during the movements from to and from to whose jump length is totally. Thus after the frog visits all the given intervals, the total jump length is .
Figure F.2 The given eight intervals
Given intervals on the line and a sequence of intervals, write a program to output the total jump length during the travel that the frog visits the intervals in order from its initial interval .
입력
Your program is to read from standard input. The input starts with a line containing two integers, and (1 ≤ n ≤ 100\,000 and 1 ≤ k ≤ 1\,000\,000), where is the number of intervals and is the number of intervals which the frog should visit. The intervals are numbered from to and the initial location of the frog is always . In the following lines, the -th line contains two integers and (0 ≤ a < b ≤ 10^9) that represent the left and right endpoints of interval , respectively. The intervals are given in increasing order of their left endpoints – if they are same, then in increasing order of the right endpoints. Also the intervals are all distinct. The next line contains integers that represent the intervals which the frog should visit in order. These integers are between and and can be in duplicate.
출력
Your program is to write to standard output. Print exactly one line. The line should contain the total jump length of frog when it visits the given intervals in order.
예제
예제 1
4 3 0 2 0 3 3 5 6 7 4 2 3
2
예제 2
4 3 0 2 0 3 3 5 6 7 2 3 2
0
예제 3
8 5 1 8 2 4 5 11 13 15 15 17 16 18 19 22 20 22 3 7 4 6 3
6