#include <bits/stdc++.h>
using namespace std;
long long q, n;
bool chec(long long cur, char qu[][2], long long op, string a) {
  long long j = 0;
  while (j < q) {
    if (a[cur] == qu[j][0]) {
      if (qu[j][1] == 'L') {
        cur--;
      } else {
        cur++;
      }
    }
    j++;
    if (cur == n) {
      if (op == 1)
        return 1;
      else
        return 0;
    }
    if (cur == -1) {
      if (op == 0)
        return 1;
      else
        return 0;
    }
  }
  return 0;
}
void run() {
  cin >> n >> q;
  string a;
  cin >> a;
  char ta[q][2];
  for (long long i = 0; i < q; i++) {
    cin >> ta[i][0] >> ta[i][1];
  }
  long long init = 0, fin = n - 1;
  long long vs = n;
  while (fin > init) {
    long long mid = (init + fin) / 2;
    if (chec(mid, ta, 1, a)) {
      vs = min(vs, mid);
      fin = mid;
    } else {
      init = mid + 1;
    }
  }
  long long ans = 0;
  ans += n - (vs);
  init = 0, fin = n - 1;
  vs = -1;
  while (fin > init) {
    long long mid = (init + fin) / 2;
    if (chec(mid, ta, 0, a)) {
      vs = max(vs, mid);
      init = mid + 1;
    } else {
      fin = mid;
    }
  }
  ans += (vs + 1);
  cout << n - ans << endl;
}
int main() {
  long long t = 1;
  for (long long i = 0; i < t; i++) run();
  return 0;
}
