#include <bits/stdc++.h>
using namespace std;
template <typename T = long long>
inline T IN() {
  T x;
  cin >> x;
  return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&...tail) {
  cin >> head;
  CIN(move(tail)...);
}
template <typename T = string>
inline void eputs(T s) {
  cout << s << "\n";
  exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
template <typename T>
using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using PQ = priority_queue<T>;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const long long LINF = 1e18;
const double PI = atan(1.0) * 4.0;
const long long dw[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dh[] = {0, 1, 1, 1, 0, -1, -1, -1};
signed main() {
  long long N, Q;
  CIN(N, Q);
  string S;
  CIN(S);
  string t, d;
  for (long long i = 0; i < (Q); ++i) {
    string tt, dd;
    CIN(tt, dd);
    t += tt;
    d += dd;
  }
  auto check = [&](long long k) {
    long long idx = k - 1;
    for (long long i = 0; i < (Q); ++i) {
      if (S[idx] == t[i]) {
        if (d[i] == 'L')
          idx--;
        else
          idx++;
        if (idx < 0)
          return -1;
        else if (idx > N - 1)
          return 1;
      }
    }
    return 0;
  };
  long long ans = 0;
  long long lb = 0, ub = N + 1;
  while (ub - lb > 1) {
    long long mid = (ub + lb) / 2;
    if (check(mid) == -1)
      lb = mid;
    else
      ub = mid;
  }
  ans += lb;
  lb = 0, ub = N + 1;
  while (ub - lb > 1) {
    long long mid = (ub + lb) / 2;
    if (check(mid) == 1)
      lb = mid;
    else
      ub = mid;
  }
  ans += lb;
  cout << N - ans << "\n";
}
