#include <bits/stdc++.h>
using namespace std;
vector<char> tv, dv;
int n, q;
string s;
int mv(int p) {
  if (p >= n) return n;
  if (p < 0) return -1;
  for (int i = 0; i < q; i++) {
    char t = tv[i], d = dv[i];
    if (s[p] == t) {
      if (d == 'L') {
        if (p == 0) return -1;
        p--;
      } else {
        if (p == n - 1) return n;
        p++;
      }
    }
  }
  return p;
}
int main() {
  char t, d;
  cin >> n >> q;
  cin >> s;
  for (int i = 0; i < q; i++) {
    cin >> t >> d;
    tv.push_back(t);
    dv.push_back(d);
  }
  int safe_l, safe_r, mid;
  int l = 0, r = n;
  while (1) {
    mid = (l + r) / 2;
    if (mv(mid) == -1 && mv(mid + 1) == -1) {
      l = mid + 1;
    } else if (mv(mid) != -1 && mv(mid + 1) != -1) {
      r = mid;
    } else
      break;
  }
  safe_l = mid + 1;
  l = 0, r = n;
  while (1) {
    mid = (l + r) / 2;
    if (mv(mid) == n && mv(mid + 1) == n) {
      r = mid;
    } else if (mv(mid) != n && mv(mid + 1) != n) {
      l = mid + 1;
    } else
      break;
  }
  safe_r = mid + 1;
  cout << (safe_r - safe_l) << endl;
}
