#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int n, q;
string s, a;
vector<int> b;
int f() {
  int l = -1, r = n - 1;
  while (r - l > 1) {
    int m = (l + r) / 2, x = m;
    for (int i = 0; i < q; i++) {
      if (s[x] == a[i]) x += b[i];
      if (x == n || x == -1) break;
    }
    if (x == -1)
      l = m;
    else
      r = m;
  }
  reverse(s.begin(), s.end());
  for (int i = 0; i < q; i++) b[i] *= -1;
  return l;
}
int main() {
  cin >> n >> q >> s;
  a = string(q, '.');
  b = vector<int>(q, 1);
  for (int i = 0; i < q; i++) {
    char c;
    cin >> a[i] >> c;
    if (c == 'L') b[i] = -1;
  }
  cout << n - 2 - f() - f() << endl;
}
