#include <bits/stdc++.h>
using namespace std;
template <typename T>
T pow(T a, T b, long long int m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
template <typename T>
T InverseMod(T a, long long int m) {
  return pow(a, m - 2, m);
}
template <typename T>
long long int SquareDist(T a, T b) {
  long long int x = abs(a.first - b.first), y = abs(a.second - b.second);
  return x * x + y * y;
}
string s, t;
std::vector<long long int> a, d, c;
std::vector<long long int> aa, dd, cc;
void solve() {
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < n; ++i) {
    string temp;
    cin >> temp;
    long long int p;
    cin >> p;
    if (temp == "ATK") {
      a.push_back(p);
    } else {
      d.push_back(p);
    }
  }
  for (long long int i = 0; i < m; ++i) {
    long long int p;
    cin >> p;
    c.push_back(p);
  }
  sort(c.begin(), c.end());
  sort(a.begin(), a.end());
  sort(d.begin(), d.end());
  long long int ans = -1;
  long long int temp = 0;
  long long int j = 0, i = m - 1;
  while (j < a.size() and i >= 0 and c[i] >= a[j]) {
    temp += (c[i] - a[j]);
    ++j, --i;
  }
  ans = max(ans, temp);
  temp = 0;
  std::vector<long long int> v = a;
  a = d;
  j = (long long int)a.size() - 1;
  while (j >= 0 and c.size()) {
    auto it = upper_bound(c.begin(), c.end(), a[j]);
    if (it == c.end()) {
      cout << ans << '\n';
      exit(0);
    }
    --j;
    c.erase(it);
  }
  a = v;
  j = (long long int)a.size() - 1;
  while (j >= 0 and c.size()) {
    auto it = lower_bound(c.begin(), c.end(), a[j]);
    if (it == c.end()) {
      cout << ans << '\n';
      exit(0);
    }
    temp += (*it - a[j]);
    --j;
    c.erase(it);
  }
  for (auto i : c) {
    temp += i;
  }
  cout << max(ans, temp) << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t--) solve();
}
