#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
const ll INF = 1e17;
const ld eps = 1e-10;
const ll MOD = 1e9 + 7;
const double pi = acos(-1.0);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, Q;
  cin >> N >> Q;
  string s;
  cin >> s;
  vector<pair<char, char>> v(Q);
  for (int q = 0; q < Q; q++) {
    char a, b;
    cin >> a >> b;
    v[q] = make_pair(a, b);
  }
  reverse(v.begin(), v.end());
  map<char, char> mp;
  for (char c = 'A'; c <= 'Z'; c++) mp[c] = 'm';
  ll left = 0;
  ll right = N - 1;
  for (int q = 0; q < Q; q++) {
    char c, move;
    tie(c, move) = v[q];
    mp[c] = move;
    if (s[left] == c && move == 'L')
      left++;
    else if (left > 0 && s[left - 1] == c && move == 'R') {
      while (left > 0 && mp[left - 1] == 'R') left--;
    }
    if (s[right] == c && move == 'R')
      right--;
    else if (right < N - 1 && s[right + 1] == c && move == 'L') {
      while (right < N - 1 && mp[right + 1] == 'L') right++;
    }
    if (left > right) break;
  }
  ll ans = min(left + N - 1 - right, N);
  cout << N - ans << endl;
  return 0;
}
