#include <bits/stdc++.h>
using namespace std;
enum Result { Left, Right, None };
struct Magic {
  char t, d;
};
Result move(string s, vector<Magic> magics, int index) {
  for (auto m : magics) {
    if (s[index] == m.t) {
      if (m.d == 'L') index--;
      if (index == -1)
        return Left;
      else
        index++;
      if (index == s.size()) return Right;
    }
  }
  return None;
}
int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<Magic> magics(q);
  for (int i = 0; i < q; i++) {
    char t, d;
    cin >> t >> d;
    magics[i] = Magic{t, d};
  }
  int l = -1, r = n;
  int lb = -1, ub = n;
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (move(s, magics, mid) == Left) {
      l = mid;
      lb = mid;
    } else {
      ub = mid;
    }
  }
  lb = -1, ub = n;
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (move(s, magics, mid) == Right) {
      r = mid;
      ub = mid;
    } else {
      lb = mid;
    }
  }
  cout << max(0, r - 1 - l) << endl;
  return 0;
}
