Fortune Telling 2

N two-sided cards start showing A_i and each threshold T_j flips every card whose visible number is at most T_j; compute the final visible sum.

Hard8Segment treeSortingSimulationNo attempts yetTime limit2sMemory limit256 MB

Problem

Professor K is the president of the Japanese committee for the International Olympiad in Informatics. He likes fortune telling and always has several kinds of it going. Today he decided to tell the fortune of this year's Japanese delegation with cards.

An integer is written on each side of every card. The two integers on one card are not necessarily different. Once a card lies on the table, only the integer on the upper side is visible and the integer on the other side is hidden.

The fortune telling goes as follows.

  • Professor K puts NN cards on the table. The cards are numbered from 1 to NN. The integer AiA_i is written on one side of card ii and the integer BiB_i is written on its other side. For every ii he puts card ii down so that AiA_i is visible.
  • For j=1,2,,Kj = 1, 2, \dots, K in this order he performs the following operation. He turns over every card whose visible integer is less than or equal to TjT_j.
  • The result of the fortune telling is the sum of the integers visible on the cards after all KK operations are finished.

Deciding which cards to turn over is a boring job, so Professor K gave up telling fortunes with cards. He only wants the sum of the integers visible on the table after all KK operations are finished.

Given the integers written on the cards and the description of the operations, write a program that computes the sum of the integers visible on the cards after every operation is finished.

Input

Read the following data from standard input.

  • The first line contains two integers NN and KK separated by a space. There are NN cards and KK operations.
  • The ii-th of the next NN lines (1iN1 \le i \le N) contains two integers AiA_i and BiB_i separated by a space. The integers written on card ii are AiA_i and BiB_i.
  • The jj-th of the next KK lines (1jK1 \le j \le K) contains an integer TjT_j. In the jj-th operation every card whose visible integer is less than or equal to TjT_j is turned over.

All input data satisfy the following conditions.

  • 1N2000001 \le N \le 200000
  • 1K2000001 \le K \le 200000
  • 1Ai10000000001 \le A_i \le 1000000000 (1iN1 \le i \le N)
  • 1Bi10000000001 \le B_i \le 1000000000 (1iN1 \le i \le N)
  • 1Tj10000000001 \le T_j \le 1000000000 (1jK1 \le j \le K)

Output

Print to standard output, on one line, the sum of the integers visible on the cards after the KK operations are finished.

Example explanation

In the first example the integers visible at the start are 4, 9, 8, 4, 3 in this order. The operations run as follows.

  • Every card whose visible integer is at most 8 is turned over. After the operation the visible integers are 6, 9, 8, 2, 7.
  • Every card whose visible integer is at most 2 is turned over. After the operation the visible integers are 6, 9, 8, 4, 7.
  • Every card whose visible integer is at most 9 is turned over. After the operation the visible integers are 4, 1, 8, 2, 3.

After all operations the sum of the visible integers is 4+1+8+2+3=184+1+8+2+3 = 18.