#include <bits/stdc++.h>
using namespace std;
struct lex_compare {
 public:
  bool operator()(const pair<long long, long long>& lhs,
                  const pair<long long, long long>& rhs) const {
    if (lhs.second == rhs.second) return lhs.first < rhs.first;
    return (lhs.second > rhs.second);
  }
};
class trp {
 public:
  long long a, b, c;
  trp() {
    this->a = 0;
    this->b = 0;
    this->c = 0;
  }
  trp(long long a, long long b, long long c) {
    this->a = a;
    this->b = b;
    this->c = c;
  }
};
class node {
 public:
  long long id, a, l;
  vector<node*> v;
  vector<pair<node*, long long>> vm;
  node() { id = 0, a = 0, l = 0; }
  void adn(node* t) {
    v.push_back(t);
    this->l++;
  }
  void adn(node* t, long long x) { vm.push_back({t, x}), l++; }
};
node* nnd(long long a = 0, long long i = 1) {
  node* t = new node();
  t->a = a;
  t->id = i;
  return t;
}
long long pw(long long a, long long b, long long m) {
  if (b == 0) return 1;
  long long t = (pw(a, b / 2, m)) % m;
  t = (t * t) % m;
  if (b % 2 == 0) return t;
  return (a * t) % m;
}
long long gc(long long a, long long b) {
  if (b == 0) return a;
  return gc(b, a % b);
}
vector<string> splt(string x, char w) {
  vector<string> v;
  string s;
  int l = x.length();
  for (int i = 0; i < l; i++) {
    if (x[i] == w) {
      v.push_back(s);
      s = "";
    } else {
      s.push_back(x[i]);
    }
  }
  v.push_back(s);
  return v;
}
void ioe() {
  freopen("in_3.txt", "r", stdin);
  freopen("out_3.txt", "w", stdout);
  freopen("er_3.txt", "w", stderr);
}
long long n, m, d = 0, c = 0, na, nd;
vector<long long> a1, a2, d1;
bool check1(long long x) {
  if (x > min(na, m)) return false;
  for (int i = 0; i < x; i++)
    if (a1[i] > a2[m - x + i]) return false;
  return true;
}
void solve() {
  cin >> n >> m;
  string s;
  long long x, y;
  d1.clear(), a1.clear(), a2.clear();
  for (int i = 0; i < n; i++) {
    cin >> s >> x;
    if (s == "DEF")
      d1.push_back(x);
    else
      a1.push_back(x);
  }
  for (int i = 0; i < m; i++) cin >> x, a2.push_back(x);
  sort(a1.begin(), a1.end());
  sort(a2.begin(), a2.end());
  sort(d1.begin(), d1.end());
  na = a1.size(), nd = d1.size(), c = 0, d = 0;
  if (n > m) c = 1;
  long long l = 0, r = min(na, m), ans = 0;
  while (l < r) {
    long long m1 = (l + r + 1) / 2;
    if (check1(m1))
      l = m1;
    else
      r = m1 - 1;
  }
  long long s1 = 0, s2 = 0;
  for (int i = 0; i < l; i++) {
    s1 += a1[i], s2 += a2[m - i - 1];
    ans = max(ans, s2 - s1);
  }
  if (l < na) {
    cout << ans << "\n";
    return;
  }
  vector<long long> v;
  x = 0, y = 0;
  long long ans1 = 0;
  while (x < nd && y < m) {
    if (d1[x] < a2[y])
      x++, y++;
    else
      v.push_back(a2[y]), y++;
  }
  if (x < nd) {
    cout << ans << "\n";
    return;
  }
  while (y < m) v.push_back(a2[y]), y++;
  m = v.size();
  for (int i = 0; i < l; i++) {
    if (v[m - l + i] < a1[i]) {
      cout << ans << "\n";
      return;
    }
    ans1 += -a1[i] + v[m - l + i];
  }
  for (int i = 0; i < m - l; i++) ans1 += v[i];
  cout << max(ans, ans1) << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  long long f = t;
  while (f--) {
    solve();
  }
}
