#include <bits/stdc++.h>
using namespace std;
template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT *delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}
int main() {
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<pair<char, char>> tds(q);
  for (auto &td : tds) {
    string a, b;
    cin >> a >> b;
    td.first = a[0];
    td.second = b[0];
  }
  int l = -1;
  int r = n;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    int x = m;
    for (auto &td : tds) {
      char tx = s[x];
      char t = td.first;
      char d = td.second;
      if (tx == t) {
        if (d == 'L') {
          x--;
        } else {
          x++;
        }
      }
      if (x < 0 || x >= n) {
        break;
      }
    }
    if (x < 0) {
      l = m;
    } else {
      r = m;
    }
  }
  int ld = l;
  l = -1;
  r = n;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    int x = m;
    for (auto &td : tds) {
      char tx = s[x];
      char t = td.first;
      char d = td.second;
      if (tx == t) {
        if (d == 'L') {
          x--;
        } else {
          x++;
        }
      }
      if (x < 0 || x >= n) {
        break;
      }
    }
    if (x >= n) {
      r = m;
    } else {
      l = m;
    }
  }
  int rd = r;
  cout << rd - ld + 1 << endl;
  return 0;
}
