#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
char s[N];
int a[N], n, m;
map<pair<char, char>, vector<int> > b;
void push(int p) {
  if (a[p]) return;
  a[p] = 1;
  if (p - 1 >= 1) b[{s[p - 1], 'R'}].push_back(p - 1);
  if (p + 1 <= n) b[{s[p + 1], 'L'}].push_back(p + 1);
}
char x[N], y[N];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  cin >> (s + 1);
  push(0), push(n + 1);
  for (int i = 0; i < m; i++) cin >> x[i] >> y[i];
  for (int i = m - 1; i >= 0; i--) {
    vector<int> v = b[{x[i], y[i]}];
    b[{x[i], y[i]}].clear();
    for (int i : v) push(i);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += a[i];
  cout << n - ans << endl;
}
