#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 18;
const long long MAX = 100005;
const long long MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1) s << "	";
  }
  return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}
string s;
long long simulate(long long pos, vector<pair<char, char>> vp) {
  for (long long i = (0); i < (vp.size()); i++) {
    if (s[pos] != vp[i].first) continue;
    if (vp[i].second == 'L') {
      pos--;
    } else {
      pos++;
    }
    if (pos < 0) return -1;
    if (pos >= s.size()) return 1;
  }
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);
  long long n, q;
  cin >> n >> q;
  cin >> s;
  vector<pair<char, char>> vp(q);
  for (long long i = (0); i < (q); i++) {
    cin >> vp[i].first >> vp[i].second;
  }
  long long ans = 0;
  long long lfall = -1;
  long long rfall = n;
  long long L = -1, R = n;
  while (L + 1 < R) {
    long long c = (L + R) / 2;
    bool ok = [&] { return simulate(c, vp) == 0; }();
    if (ok) {
      R = c;
    } else {
      L = c;
    }
  }
  lfall = L;
  L = -1, R = n;
  while (L + 1 < R) {
    long long c = (L + R) / 2;
    bool ok = [&] { return simulate(c, vp) == 1; }();
    if (ok) {
      R = c;
    } else {
      L = c;
    }
  }
  rfall = R;
  lfall = (lfall + 1);
  rfall = (n - rfall);
  cout << n - lfall - rfall << endl;
  return 0;
}
