#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> atk, def, ciel;     for (int i = 0; i < n; i++) {       string s;       int x;       cin >> s >> x;       if (s ==  ATK )         atk.push_back(x);       else         def.push_back(x);     }     for (int i = 0; i < m; i++) {       int x;       cin >> x;       ciel.push_back(x);     }     sort(atk.begin(), atk.end());     sort(def.begin(), def.end());     sort(ciel.begin(), ciel.end());     int flag = 1;     if (n >= m) flag = 0;     int ans = 0, i = m - 1, j = 0, sum = 0;     while (i >= 0 && j < atk.size()) {       if (atk[j] > ciel[i]) {         break;       }       sum += max(0, ciel[i] - atk[j]);       ans = max(ans, sum);       i--;       j++;     }     i = m - 1;     j = def.size() - 1;     int ans1 = 0, ans2 = 0;     while (i >= 0 && j >= 0) {       if (ciel[i] <= def[j]) {         flag = 0;         break;       }       i--;       j--;     }     i = 0;     vector<int> temp;     if (flag) {       j = 0;       while (i < m && j < def.size()) {         while (ciel[i] <= def[j]) {           temp.push_back(ciel[i]);           i++;           if (i == m) break;         }         i++;         j++;       }     }     while (i < m) {       temp.push_back(ciel[i]);       i++;     }     j = 0;     i = 0;     sum = 0;     int flag2 = 1;     int ans3 = 0;     while (i < temp.size() && j < atk.size()) {       while (temp[i] < atk[j]) {         ans3 += temp[i];         i++;         if (i == temp.size()) break;       }       if (i == temp.size()) break;       ans1 += temp[i] - atk[j];       i++;       j++;     }     while (i < temp.size()) {       ans3 += temp[i];       i++;     }     if (flag && j == atk.size()) ans1 += ans3;     i = temp.size() - 1;     j = 0;     while (i >= 0 && j < atk.size()) {       if (atk[j] > temp[i]) {         flag2 = 0;         break;       }       sum += max(0, temp[i] - atk[j]);       ans2 = max(ans2, sum);       i--;       j++;     }     if (flag2 && flag) {       while (i >= 0) {         ans2 += temp[i];         i--;       }     }     cout << max(ans1, ans) << endl;   }   