#include <bits/stdc++.h>
using namespace std;
int a[110] = {0};
int b[110] = {0};
int c[110] = {0};
long long ans = 0;
long long ans1 = 0;
long long ans2 = 0;
int n, m, aa, bb;
int main() {
  aa = bb = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    int x;
    cin >> s >> x;
    if (s == "DEF") {
      a[aa] = x;
      aa++;
    } else {
      b[bb] = x;
      bb++;
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i];
  }
  sort(a, a + aa);
  sort(b, b + bb);
  sort(c, c + m);
  int mm = m;
  for (int i = 1; i <= min(m, bb); i++) {
    if (b[bb - i] < c[m - i]) {
      ans2 += c[m - i] - b[bb - i];
    } else {
      break;
    }
  }
  for (int i = 0; i < bb; i++) {
    int f = 0;
    for (int j = m - 1; j >= 0; j--) {
      if (b[i] <= c[j]) {
        ans += c[j] - b[i];
        m -= 1;
        break;
      } else {
        f = 1;
        break;
      }
    }
    if (f == 1) {
      break;
    }
  }
  m = mm;
  int t = 0;
  int A = aa;
  for (int i = 0; i < aa; i++) {
    for (int j = t; j < m; j++) {
      if (a[i] < c[j]) {
        c[j] = 1000000;
        t = j + 1;
        A--;
        break;
      }
    }
  }
  sort(c, c + m);
  m -= aa;
  if (A == 0) {
    int f = 0;
    if (bb <= m) {
      for (int i = 1; i <= bb; i++) {
        if (b[bb - i] > c[m - i]) {
          f = 1;
          break;
        }
      }
      if (f == 0) {
        for (int i = 0; i < m; i++) {
          ans1 += c[i];
        }
        for (int i = 0; i < bb; i++) {
          ans1 -= b[i];
        }
      }
    }
  }
  cout << max(ans2, max(ans, ans1)) << endl;
}
