#include <bits/stdc++.h>
using namespace std;
int n, Q;
char s[200000 + 5];
char A[200000][1], B[200000][1];
bool check1(int pos) {
  char ch = s[pos];
  for (int i = 1; i <= Q; i++) {
    if (pos == 0) return 1;
    if (pos == n + 1) return 0;
    if (A[i][0] == ch) {
      pos += (B[i][0] == 'L') ? -1 : 1;
      ch = s[pos];
    }
  }
  return (pos == 0);
}
bool check2(int pos) {
  char ch = s[pos];
  for (int i = 1; i <= Q; i++) {
    if (pos == n + 1) return 1;
    if (pos == 0) return 0;
    if (A[i][0] == ch) {
      pos += (B[i][0] == 'L') ? -1 : 1;
      ch = s[pos];
    }
  }
  return (pos == n + 1);
}
int main() {
  scanf("%d%d", &n, &Q);
  scanf("%s", s + 1);
  for (int i = 1; i <= Q; i++) scanf("%s%s", A[i], B[i]);
  int l = 0, r = n, pl = 0, pr = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check1(mid)) {
      pl = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  l = 1, r = n + 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check2(mid)) {
      pr = n - mid + 1;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d", n - pl - pr);
}
