#include <bits/stdc++.h>
using namespace std;
typedef struct box {
  char name;
  int num;
} B;
int main() {
  long long n, q, ans;
  char s[300000];
  int num[300000];
  B hoge[300000];
  cin >> n >> q;
  scanf("%s", s);
  hoge[0].name = 'H';
  hoge[0].num = 0;
  hoge[n + 1].name = 'H';
  hoge[n + 1].num = 0;
  for (int i = 0; i < n; i++) {
    hoge[i + 1].name = s[i];
    hoge[i + 1].num = 1;
  }
  char first, second;
  for (int i = 0; i < q; i++) {
    getchar();
    first = getchar();
    getchar();
    second = getchar();
    for (int j = 1; j <= n; j++) {
      if (first == hoge[j].name) {
        if (second == 'R') {
          hoge[j + 1].num += hoge[j].num;
        } else {
          hoge[j - 1].num += hoge[j].num;
        }
        hoge[j].num = 0;
        hoge[0].num = 0;
        hoge[n + 1].num = 0;
      }
    }
  }
  ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += hoge[i].num;
  }
  cout << ans << endl;
  return 0;
}
