#include <bits/stdc++.h>
using namespace std;
int atk[102], def[102], my[102];
int solve1(int m, int a) {
  int ans = 0;
  int j = 0;
  for (int i = m - 1; i >= 0; --i) {
    if (j < a && my[i] >= atk[j]) {
      ans += my[i] - atk[j++];
    } else {
      break;
    }
  }
  return ans;
}
int solv(int m, int a, int b) {
  int k = 0, l = 0, sol2 = 0;
  vector<int> del(m, 0);
  while (k < b && l < m) {
    if (def[k] < my[l]) {
      k++;
      del[l] = 1;
      l++;
    } else {
      l++;
    }
  }
  if (k != b) {
    sol2 = 0;
    return 0;
  }
  k = 0;
  l = 0;
  while (k < a && l < m) {
    if (del[l] == 1) {
      l++;
      continue;
    }
    if (atk[k] <= my[l]) {
      del[l] = 1;
      sol2 += my[l] - atk[k];
      k++;
      l++;
    } else {
      l++;
    }
  }
  if (k != a) {
    return sol2;
  }
  for (int i = 0; i < m; i++) {
    if (del[i] == 1) continue;
    sol2 += my[i];
  }
  return sol2;
}
int solve2(int m, int a, int d) {
  vector<int> del(m, 0);
  int j = 0;
  for (int i = 0; i < d; ++i) {
    while (j < m && my[j] <= def[i]) {
      j++;
    }
    if (j >= m) {
      return -1;
    } else {
      del[j] = 1;
      j++;
    }
  }
  j = 0;
  int ans = 0;
  for (int i = 0; i < a; ++i) {
    while (j < m && (del[j] || my[j] < atk[i])) {
      j++;
    }
    if (j >= m) return ans;
    ans += my[j] - atk[i];
    del[j] = 1;
    j++;
  }
  for (int i = 0; i < m; ++i) {
    if (!del[i]) {
      ans += my[i];
    }
  }
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  string s;
  int a = 0, d = 0, x;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    cin >> x;
    if (s[0] == 'A') {
      atk[a++] = x;
    } else {
      def[d++] = x;
    }
  }
  for (int i = 0; i < m; ++i) {
    cin >> x;
    my[i] = x;
  }
  sort(atk, atk + a);
  sort(def, def + d);
  sort(my, my + m);
  int sol1 = solve1(m, a);
  int sol2 = solve2(m, a, d);
  cout << max(sol1, sol2) << "\n";
  return 0;
}
