#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long int maxn = 1e3 + 1;
void solve() {
  long long int n, m;
  cin >> n >> m;
  vector<pair<long long int, long long int>> jiro;
  for (long long int i = 0; i < n; i++) {
    string s;
    cin >> s;
    long long int x, y;
    if (s == "ATK")
      x = 1;
    else
      x = 0;
    cin >> y;
    jiro.push_back(make_pair(y, x));
  }
  sort(jiro.begin(), jiro.end());
  long long int ciel[m];
  for (long long int i = 0; i < m; i++) {
    cin >> ciel[i];
  }
  sort(ciel, ciel + m);
  long long int ans = 0;
  long long int k = m - 1;
  for (long long int i = 0; i < n; i++) {
    if (jiro[i].second == 1) {
      if (ciel[k] > jiro[i].first) {
        ans += (ciel[k] - jiro[i].first);
        k--;
      } else
        break;
    }
    if (k < 0) break;
  }
  if (m >= n) {
    long long int flag = 1;
    k = m - 1;
    for (long long int i = n - 1; i >= 0; i--) {
      if (jiro[i].second and jiro[i].first > ciel[k]) flag = 0;
      if (jiro[i].second == 0 and ciel[k] <= jiro[i].first) flag = 0;
      k--;
    }
    if (flag) {
      for (long long int i = 0; i < n; i++) {
        if (jiro[i].second == 0) {
          for (long long int j = 0; j < m; j++) {
            if (ciel[j] > jiro[i].first) {
              ciel[j] = 0;
              break;
            }
          }
        }
      }
      long long int cc = 0, bb = 0;
      for (long long int i = 0; i < n; i++) {
        if (jiro[i].second == 1) bb += jiro[i].first;
      }
      for (long long int i = 0; i < m; i++) {
        cc += ciel[i];
      }
      ans = max(ans, cc - bb);
    }
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
