#include <bits/stdc++.h>
using namespace std;
long long A[101][101];
unsigned int ans[101];
const long long INF = 1000LL * 1000LL * 1000LL * 1000LL * 100LL;
template <typename T>
T hungarian(T a[101][101], unsigned int n, unsigned int m, const T INF,
            unsigned int* ans, bool maxcost) {
  vector<T> u(n + 1), v(m + 1);
  vector<unsigned int> way(m + 1), p(m + 1);
  if (maxcost)
    for (unsigned int i = 0; i < n; ++i)
      for (unsigned int j = 0; j < m; ++j) a[i][j] = -a[i][j];
  for (unsigned int i = 1; i <= n; ++i) {
    p[0] = i;
    unsigned int j0 = 0;
    vector<T> minv(m + 1, INF);
    vector<char> used(m + 1, false);
    do {
      used[j0] = true;
      unsigned int i0 = p[j0], j1, j;
      T delta = INF;
      for (j = 1; j <= m; ++j)
        if (!used[j]) {
          T cur = (i0 ? a[i0 - 1][j - 1] : 0) - u[i0] - v[j];
          if (cur < minv[j]) minv[j] = cur, way[j] = j0;
          if (minv[j] < delta) delta = minv[j], j1 = j;
        }
      for (j = 0; j <= m; ++j)
        if (used[j])
          u[p[j]] += delta, v[j] -= delta;
        else
          minv[j] -= delta;
      j0 = j1;
    } while (p[j0] != 0);
    do {
      unsigned int j1 = way[j0];
      p[j0] = p[j1];
      j0 = j1;
    } while (j0);
  }
  if (ans)
    for (unsigned int j = 0; j < m; ++j) ans[p[j + 1] - 1] = j;
  if (maxcost) {
    for (unsigned int i = 0; i < n; ++i)
      for (unsigned int j = 0; j < m; ++j) a[i][j] = -a[i][j];
    return v[0];
  }
  return -v[0];
}
vector<pair<bool, int> > jiro, ciel;
int n, m;
int main() {
  cin.sync_with_stdio(false);
  cin >> n >> m;
  int i;
  for (i = 0; i < (n); ++i) {
    char s[8];
    int p;
    cin >> s >> p;
    jiro.push_back(make_pair(s[0] == 'A', p));
  }
  for (i = 0; i < (m); ++i) {
    int p;
    cin >> p;
    ciel.push_back(make_pair(true, p));
  }
  int x = max(n, m);
  for (i = 0; i < (x); ++i) {
    int p = (i < m) ? ciel[i].second : 0;
    int j;
    for (j = 0; j < (x); ++j) {
      if (j < n) {
        if (jiro[j].first) {
          if (p >= jiro[j].second)
            A[i][j] = p - jiro[j].second;
          else
            A[i][j] = -80000000;
        } else {
          if (p > jiro[j].second)
            A[i][j] = 0;
          else
            A[i][j] = -80000000;
        }
      } else {
        A[i][j] = p;
      }
    }
  }
  long long cost1 =
      hungarian(A, (unsigned int)x, (unsigned int)x, INF, 0, true);
  for (i = 0; i < (x); ++i) {
    int p = (i < m) ? ciel[i].second : 0;
    int j;
    for (j = 0; j < (x); ++j) {
      if (j < n) {
        if (jiro[j].first) {
          if (p >= jiro[j].second)
            A[i][j] = p - jiro[j].second;
          else
            A[i][j] = 0;
        } else {
          if (p > jiro[j].second)
            A[i][j] = 0;
          else
            A[i][j] = 0;
        }
      } else {
        A[i][j] = 0;
      }
    }
  }
  long long cost2 =
      hungarian(A, (unsigned int)x, (unsigned int)x, INF, 0, true);
  cout << max(cost1, cost2) << endl;
  return 0;
}
