#include <bits/stdc++.h>
using namespace std;
char str[202020], DM[202020];
int dr[202020], ch[202020];
int n, m;
bool left(int p) {
  for (int i = 0; i < m; i++) {
    if (str[p] - 'A' == ch[i]) {
      p += dr[i];
      if (p < 0) return true;
      if (p >= n) return false;
    }
  }
  return false;
}
bool right(int p) {
  for (int i = 0; i < m; i++) {
    if (str[p] - 'A' == ch[i]) {
      p += dr[i];
      if (p < 0) return false;
      if (p >= n) return true;
    }
  }
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  scanf("%s", &str);
  for (int i = 0; i < m; i++) {
    scanf("%s", &DM);
    ch[i] = DM[0] - 'A';
    scanf("%s", &DM);
    if (DM[0] == 'L')
      dr[i] = -1;
    else
      dr[i] = 1;
  }
  int ret = n;
  int l = -1, r = n;
  while (r - 1 > 1) {
    int d = (l + r) / 2;
    if (left(d))
      l = d;
    else
      r = d;
  }
  ret -= r;
  l = -1, r = n;
  while (r - l > 1) {
    int d = (l + r) / 2;
    if (right(d))
      r = d;
    else
      l = d;
  }
  ret -= n - r;
  printf("%d\n", ret);
  return 0;
}
