#include <bits/stdc++.h>
int char_to_int(char c) { return (int)c - (int)'A'; }
char int_to_char(int x) { return (char)(x + (int)'A'); }
int main() {
  int N, Q, i, j, k, f;
  scanf("%d%d", &N, &Q);
  char *s = (char *)malloc(sizeof(char) * (N + 1));
  scanf("%s", s);
  char *t = (char *)malloc(sizeof(char) * Q);
  char *d = (char *)malloc(sizeof(char) * Q);
  char sub[2];
  for (i = 0; i < Q; i++) {
    scanf("%s", sub);
    t[i] = sub[0];
    scanf("%s", sub);
    d[i] = sub[0];
  }
  int **next = (int **)malloc(sizeof(int *) * (Q + 1));
  for (i = 0; i <= Q; i++) {
    next[i] = (int *)malloc(sizeof(int) * 26);
  }
  for (j = 0; j < 26; j++) {
    next[Q][j] = Q;
  }
  for (i = Q - 1; i >= 0; i--) {
    for (j = 0; j < 26; j++) {
      if (t[i] == int_to_char(j)) {
        next[i][j] = i;
      } else {
        next[i][j] = next[i + 1][j];
      }
    }
  }
  int ans = 0;
  for (i = 0; i < N; i++) {
    f = 1;
    for (j = i, k = next[0][char_to_int(s[j])]; k < Q;
         k = next[k + 1][char_to_int(s[j])]) {
      if (d[k] == 'L') {
        j--;
      } else {
        j++;
      }
      if (j < 0 || N <= j) {
        f = 0;
        break;
      }
    }
    ans += f;
  }
  printf("%d\n", ans);
  return 0;
}
