#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int first;
  int second;
  int third;
} T;
bool comp_Se(T& l, T& r) { return l.second < r.second; }
int N, Q;
string s;
vector<pair<char, char> > v;
int fall(int x) {
  if (x < 0)
    return 1;
  else if (x >= N)
    return 2;
  int i;
  for (i = 0; i < v.size(); i++) {
    if (v[i].first == s[x]) {
      if (v[i].second == 'L')
        x--;
      else
        x++;
    }
    if (x < 0)
      return 1;
    else if (x >= N)
      return 2;
  }
  return 0;
}
int binary_search(int start, int end, int mode) {
  while (true) {
    int mid = (start + end) / 2;
    int f = fall(mid);
    if (end - start <= 1) break;
    if (mode) {
      if (!f)
        start = mid;
      else
        end = mid;
    } else {
      if (!f)
        end = mid;
      else
        start = mid;
    }
  }
  return end;
}
int main(void) {
  int i, j;
  cin >> N >> Q;
  cin >> s;
  for (i = 0; i < Q; i++) {
    char x, y;
    cin >> x >> y;
    v.push_back(pair<char, char>(x, y));
  }
  int start = 0, end = N, mid;
  while (true) {
    mid = (start + end) / 2;
    int f = fall(mid);
    if (!f)
      break;
    else if (f == 1)
      start = mid;
    else
      end = mid;
    if (end - start < 1) break;
  }
  int S, E;
  if (fall(start) % 2 == 0)
    S = start;
  else
    S = binary_search(start, mid, 0);
  if (fall(end) != 2)
    E = end + 1;
  else
    E = binary_search(mid, end, 1);
  cout << E - S << endl;
  return 0;
}
