#include <bits/stdc++.h>
namespace IO {
template <typename T>
inline void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  x *= f;
  return;
}
template <typename T>
inline void write(T x = 0) {
  T wr[51];
  wr[0] = 0;
  if (x < 0) putchar('-'), x = -x;
  if (!x) putchar(48);
  while (x) wr[++wr[0]] = x % 10, x /= 10;
  while (wr[0]) putchar(48 + wr[wr[0]--]);
  return;
}
}  // namespace IO
using IO::read;
using IO::write;
using namespace std;
const int N = 1e5 + 11;
int n, m;
char c[3];
char s[N], id[N], op[N];
int mx[27], mn[27], p[27], hv[N];
inline bool check1(int x) {
  for (register int i = 1; i <= m; ++i) {
    if (id[i] == s[x]) {
      if (op[i] == 'L')
        --x;
      else
        ++x;
    }
    if (x < 1) return 1;
  }
  return 0;
}
inline bool check2(int x) {
  for (register int i = 1; i <= m; ++i) {
    if (id[i] == s[x]) {
      if (op[i] == 'L')
        --x;
      else
        ++x;
    }
    if (x > n) return 1;
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%s", s + 1);
  for (register int i = 1; i <= m; ++i) {
    scanf("%s%s", c, c + 1);
    id[i] = c[0], op[i] = c[1];
  }
  if (check1(n) || check2(1)) {
    puts("0");
    return 0;
  }
  int l = 0;
  for (register int i = log2(n); i >= 0; --i)
    if (check1(l | (1 << i))) l |= (1 << i);
  int r = 0;
  for (register int i = log2(n); i >= 0; --i)
    if (check2(n + 1 - (r | (1 << i)))) r |= (1 << i);
  printf("%d\n", n - r - l);
  return 0;
}
