#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int n, q;
string s;
vector<char> t;
vector<char> d;
bool ok(int x) {
  bool flag = true;
  for (int i = 0; i < q; ++i) {
    if (s[x] == t[i]) {
      if (d[i] == 'L')
        --x;
      else
        ++x;
      if (x < 0 || n <= x) {
        flag = false;
        break;
      }
    }
  }
  return flag;
}
char ok2(int x) {
  bool flag = true;
  for (int i = 0; i < q; ++i) {
    if (s[x] == t[i]) {
      if (d[i] == 'L')
        --x;
      else
        ++x;
      if (x < 0 || n <= x) {
        flag = false;
        break;
      }
    }
  }
  if (flag)
    return 'T';
  else {
    if (x < 0)
      return 'L';
    else
      return 'R';
  }
}
int main() {
  cin >> n >> q;
  cin >> s;
  for (int i = 0; i < q; ++i) {
    char tmp0, tmp1;
    cin >> tmp0 >> tmp1;
    t.push_back(tmp0);
    d.push_back(tmp1);
  }
  bool a = ok(0), b = ok(n - 1);
  if (a && b) {
    cout << n << endl;
    return 0;
  }
  int ans;
  if (a && !b) {
    int l = 0, r = n - 1, mid;
    while (r - l > 1) {
      mid = (l + r) / 2;
      cout << mid << ": " << ok(mid) << endl;
      if (ok(mid)) {
        l = mid;
      } else {
        r = mid;
      }
    }
    ans = (n - l - 1);
  } else if (!a && b) {
    int l = 0, r = n - 1, mid;
    while (r - l > 1) {
      mid = (l + r) / 2;
      if (ok(mid)) {
        r = mid;
      } else {
        l = mid;
      }
    }
    ans = n - l - 1;
  } else {
    int k = -1;
    int l_ = 0, r_ = n - 1, mid_;
    bool fla = false;
    while (r_ - l_ > 1) {
      mid_ = (l_ + r_) / 2;
      if (ok2(mid_) == 'T') {
        k = mid_;
        fla = true;
        break;
      } else if (ok2(mid_) == 'L') {
        l_ = mid_;
      } else {
        r_ = mid_;
      }
    }
    if (k == -1) {
      cout << 0 << endl;
      return 0;
    }
    {
      int l = 0, r = k, mid;
      while (r - l > 1) {
        mid = (l + r) / 2;
        if (ok(mid)) {
          r = mid;
        } else {
          l = mid;
        }
      }
      cout << (l + 1) << endl;
      ans += (l + 1);
    }
    {
      int l = k, r = n - 1, mid;
      while (r - l > 1) {
        mid = (l + r) / 2;
        if (ok(mid)) {
          l = mid;
        } else {
          r = mid;
        }
      }
      cout << (n - l - 1) << endl;
      ans += (n - l - 1);
    }
    ans = n - ans;
  }
  cout << ans << endl;
  return 0;
}
