#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (auto i : v) os << i <<    ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& v) {     for (auto i : v) os << i <<    ;     return os;   }   template <typename T>   T read() {     char c = getchar();     T sgn = 1;     T t = 0;     while (!isdigit(c)) {       if (c ==  - ) sgn = -sgn;       c = getchar();     }     while (isdigit(c)) {       t *= 10;       t += c -  0 ;       c = getchar();     }     return t * sgn;   }   const int N = 1e5;   vector<int> atk, def, had;   bool used[N];   int main() {     int n = read<int>();     int m = read<int>();     for (int i = 0; i < n; ++i) {       char s[10];       int val;       scanf( %s %d , s, &val);       getchar();       if (s[0] ==  A ) atk.push_back(val);       if (s[0] ==  D ) def.push_back(val);     }     for (int i = 0; i < m; ++i) had.push_back(read<int>());     sort(atk.begin(), atk.end());     sort(def.begin(), def.end());     sort(had.begin(), had.end());     int ans = 0;     for (int i = m - 1; i >= 0; --i) {       int cur = 0;       for (int j = 0, t = atk.size(); j < m - i && j < t; ++j)         if (had[i + j] >= atk[j]) cur += had[i + j] - atk[j];       ans = max(ans, cur);     }     int p = 0;     for (auto i : def) {       while (p < m && had[p] <= i) p++;       if (p == m) {         printf( %d n , ans);         exit(0);       }       used[p] = true;       p++;     }     p = m - 1;     int ans2 = 0;     for (int i = atk.size() - 1; i >= 0; --i) {       int j = atk[i];       while (p >= 0 && used[p]) p--;       if (p == -1 || had[p] < j) {         printf( %d n , ans);         exit(0);       }       ans2 += had[p] - j;       used[p] = true;       p--;     }     for (int i = 0; i < m; ++i)       if (!used[i]) ans2 += had[i];     printf( %d n , max(ans, ans2));     return 0;   }   