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

B. Ciel and Duel

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputFox Ciel is playing a card game with her friend Jiro.

Jiro has *n* cards, each one has two attributes: *position* (Attack or Defense) and *strength*. Fox Ciel has *m* cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.

Now is Ciel's battle phase, Ciel can do the following operation many times:

- Choose one of her cards
*X*. This card mustn't be chosen before. - If Jiro has no alive cards at that moment, he gets the damage equal to (
*X*'s strength). Otherwise, Ciel needs to choose one Jiro's alive card*Y*, then:- If
*Y*'s position is Attack, then (*X*'s strength) ≥ (*Y*'s strength) must hold. After this attack, card*Y*dies, and Jiro gets the damage equal to (*X*'s strength) - (*Y*'s strength). - If
*Y*'s position is Defense, then (*X*'s strength) > (*Y*'s strength) must hold. After this attack, card*Y*dies, but Jiro gets no damage.

- If

Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get.

Input

The first line contains two integers *n* and *m* (1 ≤ *n*, *m* ≤ 100) — the number of cards Jiro and Ciel have.

Each of the next *n* lines contains a string *position* and an integer *strength* (0 ≤ *strength* ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense.

Each of the next *m* lines contains an integer *strength* (0 ≤ *strength* ≤ 8000) — the strength of Ciel's current card.

Output

Output an integer: the maximal damage Jiro can get.

Examples

Input

2 3

ATK 2000

DEF 1700

2500

2500

2500

Output

3000

Input

3 4

ATK 10

ATK 100

ATK 1000

1

11

101

1001

Output

992

Input

2 4

DEF 0

ATK 0

0

0

1

1

Output

1

Note

In the first test case, Ciel has 3 cards with same *strength*. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000.

In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992.

In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card.

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/22/2019 07:54:52 (h1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|