#include <bits/stdc++.h>
using namespace std;
int n, m;
int res1, res2;
vector<int> atk;
vector<int> def;
vector<int> data;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    char t[100] = {
        0,
    };
    int a;
    scanf("%s %d\n", t, &a);
    if (t[0] == 'A')
      atk.push_back(a);
    else
      def.push_back(a);
  }
  for (int i = 1; i <= m; i++) {
    int a;
    scanf("%d", &a);
    data.push_back(a);
  }
  sort(data.begin(), data.end());
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  for (int k = 0; k <= min(data.size(), atk.size()); k++) {
    vector<int> t1, t2;
    for (int i = 0; i < k; i++) t1.push_back(data[data.size() - i - 1]);
    for (int i = 0; i < k; i++) t2.push_back(atk[i]);
    bool flag = false;
    for (int i = 0; i < k; i++) {
      if (t1[i] < t2[k - i - 1]) {
        flag = true;
        break;
      }
    }
    if (!flag) {
      int temp = 0;
      for (int i = 0; i < k; i++) {
        temp += t1[i] - t2[i];
      }
      res1 = max(res1, temp);
    }
  }
  bool def_check = false;
  for (int i = 0; i < def.size(); i++) {
    bool check = false;
    for (int j = 0; j < data.size(); j++) {
      if (data[j] > def[i]) {
        data[j] = -1;
        check = true;
        break;
      }
    }
    if (!check) {
      def_check = true;
      break;
    }
  }
  if (!def_check) {
    sort(data.begin(), data.end());
    int from = data.size();
    for (int i = 0; i < data.size(); i++) {
      if (data[i] != -1) {
        from = i;
        break;
      }
    }
    if (data.size() - from < atk.size()) {
      res2 = 0;
    } else {
      int p = data.size() - 1;
      int q = atk.size() - 1;
      bool check = false;
      for (int i = from; i < data.size(); i++) {
        if (p < 0 || q < 0) {
          break;
        }
        if (data[p] < atk[q]) {
          check = true;
          break;
        }
        p--;
        q--;
      }
      if (check)
        res2 = 0;
      else {
        for (int i = from; i < data.size(); i++) res2 += data[i];
        for (int i = 0; i < atk.size(); i++) res2 -= atk[i];
      }
    }
  } else
    res2 = 0;
  printf("%d\n", max(res1, res2));
  return 0;
}
