#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-24;
const double PI = acos(-1.0);
const int inf = int(1e9 + 7);
const long long INF = (long long)8e18 + 7;
const int mod = int(1e9 + 7);
const int N = int(2e5 + 7);
int n, m, a[105], ans;
multiset<int> second;
vector<int> v[2];
void face() {
  int res = 0;
  for (int i = 0; i < v[1].size(); i++) {
    auto it = second.upper_bound(v[1][i]);
    if (it == second.end()) return;
    second.erase(it);
  }
  int sum1 = 0, sum2 = 0;
  for (int it : v[0]) sum1 += it;
  for (auto it : second) sum2 += it;
  for (int to : v[0]) {
    auto it = second.lower_bound(to);
    if (it == second.end()) return;
    second.erase(it);
  }
  ans = max(ans, sum2 - sum1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0, x; i < n; i++) {
    string t;
    cin >> t >> x;
    if (t[0] == 'A')
      v[0].push_back(x);
    else
      v[1].push_back(x);
  }
  sort(v[0].begin(), v[0].end());
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    second.insert(a[i]);
  }
  sort(a, a + m);
  face();
  for (int i = 0; i < v[0].size(); i++) {
    int res = 0, k = m - 1;
    for (int j = i; k >= 0 && j >= 0; k--, j--) {
      res += max(0, a[k] - v[0][j]);
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}
