#include <bits/stdc++.h>
using namespace std;
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
string strin() {
  string s;
  cin >> s;
  return s;
}
char chin() {
  char c;
  cin >> c;
  return c;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
vector<pair<char, char>> p;
int n, q;
string s;
int check(int x) {
  int now = x;
  for (long long i = 0; i < q; i++) {
    if (s.at(now) == p[i].first) {
      if (p[i].second == 'L')
        now--;
      else
        now++;
      if (now == -1) return 1;
      if (now == n) return 2;
    }
  }
  return 0;
}
int main() {
  n = in();
  q = in();
  s = strin();
  for (long long i = 0; i < n; i++) p.push_back({chin(), chin()});
  int l = 0, r = n + 1, ans = 0;
  while (l + 1 < r) {
    int mid = (l + r) / 2, a = check(mid - 1);
    if (a == 1)
      l = mid;
    else
      r = mid;
  }
  ans += l;
  l = 0;
  r = n + 1;
  while (l + 1 < r) {
    int mid = (l + r) / 2, a = check(n - mid);
    if (a == 2)
      l = mid;
    else
      r = mid;
  }
  ans += l;
  cout << max(n - ans, 0) << endl;
}
