#include <bits/stdc++.h>
int main() {
  int N;
  int Q;
  char s[200002];
  int s_f[200002];
  int i;
  int j;
  char si;
  char bi;
  char t[4];
  int count = 0;
  int temp;
  scanf("%d", &N);
  scanf("%d", &Q);
  for (i = 0; i < N; i++) {
    s_f[i] = 1;
  }
  scanf("%s", &s[0]);
  for (i = 0; i < Q; i++) {
    scanf("%s", &t[0]);
    si = t[0];
    scanf("%s", &t[0]);
    bi = t[0];
    for (j = 0; j < N; j++) {
      if (s[j] == si) {
        if (bi == 'R') {
          temp = s_f[j];
          s_f[j] = 0;
          s_f[j + 1] += temp;
        } else if (bi == 'L') {
          temp = s_f[j];
          s_f[j] = 0;
          if (j - 1 >= 0) {
            s_f[j - 1] += temp;
          }
        }
      }
    }
  }
  for (i = 0; i < N; i++) {
    count += s_f[i];
  }
  printf("%d\n", count);
  return 0;
}
