#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
const long double pi = acos(-1);
int N, M;
vector<int> mine;
vector<int> atk;
vector<int> def;
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(15);
  cout << fixed;
  cout.tie(0);
  cin >> N >> M;
  for (int(i) = 1, j123 = N; (i) <= j123; (i)++) {
    string s;
    int x;
    cin >> s >> x;
    if (s == "ATK")
      atk.push_back(x);
    else
      def.push_back(x);
  }
  for (int(i) = 1, j123 = M; (i) <= j123; (i)++) {
    int foo;
    cin >> foo;
    mine.push_back(foo);
  }
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  sort(mine.begin(), mine.end());
  reverse(mine.begin(), mine.end());
  int ans = 0;
  for (int i = 0; i < min(int(atk.size()), int(mine.size())); i++) {
    int good = 1;
    for (int ii = 0; ii <= i; ii++) {
      good &= (mine[i - ii] >= atk[ii]);
    }
    if (good) {
      int tot = 0;
      for (int ii = 0; ii <= i; ii++) {
        tot += mine[ii] - atk[ii];
      }
      ans = max(ans, tot);
    }
  }
  if (int(mine.size()) >= int(atk.size()) + int(def.size())) {
    vector<int> leftover;
    int j = int(mine.size()) - 1;
    int bad = 0;
    for (int i = 0; i < int(def.size()); i++) {
      while (j >= 0 && mine[j] <= def[i]) {
        leftover.push_back(mine[j]);
        j--;
      }
      if (j < 0) {
        bad = 1;
        break;
      }
      j--;
    }
    while (j >= 0) {
      leftover.push_back(mine[j]);
      j--;
    }
    if (!bad && (int(leftover.size()) > int(atk.size()))) {
      int good = 1;
      sort(leftover.begin(), leftover.end());
      reverse(leftover.begin(), leftover.end());
      for (int(i) = 0, j123 = int(atk.size()); (i) < j123; (i)++)
        good &= (atk[int(atk.size()) - 1 - i] <= leftover[i]);
      if (good) {
        int dmg = 0;
        for (int(i) = 0, j123 = int(leftover.size()); (i) < j123; (i)++)
          dmg += leftover[i];
        for (int(i) = 0, j123 = int(atk.size()); (i) < j123; (i)++)
          dmg -= atk[i];
        ans = max(ans, dmg);
      }
    }
  }
  cout << ans << '\n';
}
