human
CPP solution for "Fox 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:

  1. Choose one of her cards X. This card mustn't be chosen before. 
  2. 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. 


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...":



=====
Can you provide a Python code to calculate the maximal sum of damage Jiro can get?
assistant
#Here is Python code to calculate the maximal sum of damage Jiro can get.
 #include <bits/stdc++.h>
using namespace std;
const int MX = 109;
int n, m;
int ciel[MX];
int atk[MX], def[MX];
int cnt_atk, cnt_def;
int solve_all(void) {
  int result = 0, iter_atk = 0, iter_def = 0;
  for (int i = 0; i < m; i++) {
    if (iter_def < cnt_def && ciel[i] > def[iter_def])
      iter_def++;
    else if (iter_atk < cnt_atk && ciel[i] >= atk[iter_atk]) {
      result += ciel[i] - atk[iter_atk];
      iter_atk++;
    } else
      result += ciel[i];
  }
  if (iter_atk < cnt_atk || iter_def < cnt_def) return 0;
  return result;
}
int solve_only_atk(void) {
  int result = 0;
  for (int i = m - 1, j = 0; i >= 0 && j < cnt_atk && ciel[i] >= atk[j];
       i--, j++) {
    result += ciel[i] - atk[j];
  }
  return result;
}
int main() {
  cin >> n >> m;
  cnt_atk = 0, cnt_def = 0;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "ATK")
      cin >> atk[cnt_atk++];
    else
      cin >> def[cnt_def++];
  }
  for (int i = 0; i < m; i++) cin >> ciel[i];
  sort(ciel, ciel + m);
  sort(atk, atk + cnt_atk);
  sort(def, def + cnt_def);
  int result = 0;
  result = max(result, solve_all());
  result = max(result, solve_only_atk());
  cout << result;
  return 0;
}