#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-11;
const double pi = acos(-1.0);
const int p = 1000000007;
int countbit(int n) { return n == 0 ? 0 : countbit(n / 2) + n % 2; }
int lowbit(int n) { return (n ^ (n - 1)) & n; }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long toInt64(string s) {
  istringstream sin(s);
  long long t;
  sin >> t;
  return t;
}
string toStr(long long t) {
  stringstream sin;
  sin << t;
  string s;
  sin >> s;
  return s;
}
template <typename T>
T sqr(T n) {
  return n * n;
}
template <typename T>
void out(T& v) {
  for (int i = 0; i < v.size(); i++)
    cout << v[i] << (i == v.size() - 1 ? '\n' : ' ');
}
class Timer {
 public:
  double start;
  Timer() { start = static_cast<double>(clock()); }
  void out() { cout << "TIME: " << (clock() - start) / CLOCKS_PER_SEC << endl; }
};
void solve() {
  int n_jiro, n_ciel;
  cin >> n_jiro >> n_ciel;
  vector<int> atk, def;
  for (int i = 0; i < n_jiro; ++i) {
    string s;
    int val;
    cin >> s >> val;
    if (s == "ATK")
      atk.push_back(val);
    else
      def.push_back(val);
  }
  sort(atk.begin(), atk.end(), greater<int>());
  sort(def.begin(), def.end(), greater<int>());
  vector<int> ciel(n_ciel);
  for (int i = 0; i < n_ciel; ++i) cin >> ciel[i];
  sort(ciel.begin(), ciel.end(), greater<int>());
  int atk_only = 0;
  for (int i = 0; i < min((int)atk.size(), n_ciel); ++i) {
    int val = atk[atk.size() - i - 1];
    if (ciel[i] > val) {
      atk_only += ciel[i] - val;
    } else
      break;
  }
  int with_def = 0;
  bool possible = true;
  if (n_ciel > n_jiro) {
    list<int> ciel_lst(ciel.begin(), ciel.end());
    reverse(ciel_lst.begin(), ciel_lst.end());
    for (int df : def) {
      auto it = upper_bound(ciel_lst.begin(), ciel_lst.end(), df);
      if (it == ciel_lst.end()) {
        possible = false;
        break;
      }
      ciel_lst.erase(it);
    }
    if (possible) {
      for (int at : atk) {
        auto it = upper_bound(ciel_lst.begin(), ciel_lst.end(), at,
                              less_equal<int>());
        if (it == ciel_lst.end()) {
          possible = false;
          break;
        }
        with_def += (*it) - at;
        ciel_lst.erase(it);
      }
      with_def = accumulate(ciel_lst.begin(), ciel_lst.end(), with_def);
    }
  }
  cout << max((possible ? with_def : 0), atk_only) << endl;
}
int main() {
  cout.sync_with_stdio(false);
  cin.sync_with_stdio(false);
  solve();
  return EXIT_SUCCESS;
}
