#include <bits/stdc++.h>
using namespace std;
char A[100000], B[100000];
long long n, k, s, g, m, ans;
string t;
bool f(long long p, long long q) {
  for (int i = 0; i < k; i++) {
    if (A[i] == t[p]) {
      if (B[i] == 'L')
        p--;
      else
        p++;
    }
  }
  if (p == q) return true;
  return false;
}
int main(void) {
  cin >> n >> k >> t;
  t = '#' + t + '#';
  for (int i = 0; i < k; i++) cin >> A[i] >> B[i];
  s = 0, g = n + 1;
  while (g - s > 1) {
    m = (g + s) / 2;
    if (f(m, 0))
      s = m;
    else
      g = m;
  }
  ans += s;
  s = 0, g = n + 1;
  while (g - s > 1) {
    m = (g + s) / 2;
    if (f(m, n + 1))
      g = m;
    else
      s = m;
  }
  ans += n - s;
  cout << n - ans << endl;
}
