#include <bits/stdc++.h>
using namespace std;
inline void logger() { std::cout << " [LOGGER] " << endl; }
template <typename A, typename... B>
void logger(const A& a, const B&... b) {
  cout << a << " , ";
  logger(b...);
}
const long long MOD = 1000000007;
const long long MOD9 = 998244353;
const long long INF = MOD * MOD;
const int MAX = 200005;
int n, q;
string s;
char vq[MAX][2];
int solve(int i) {
  for (int(j) = 0; (j) < (q); (j)++) {
    if (s[i] != vq[j][0]) continue;
    if (vq[j][1] == 'L')
      i--;
    else
      i++;
    if (i < 0 || i >= n) return i;
  }
  return i;
}
int main() {
  cin >> n >> q >> s;
  for (int(i) = 0; (i) < (q); (i)++) cin >> vq[i][0] >> vq[i][1];
  int ok = -1, ng = n;
  while (ng - ok > 1) {
    int mid = (ok + ng) / 2;
    if (solve(mid) < 0)
      ok = mid;
    else
      ng = mid;
  }
  int ans = ok + 1;
  ng = -1, ok = n;
  while (ok - ng > 1) {
    int mid = (ok + ng) / 2;
    if (solve(mid) >= n)
      ok = mid;
    else
      ng = mid;
  }
  ans += n - ok;
  cout << (n - ans) << endl;
}
