#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  char rl, arufa;
  cin >> n >> q;
  vector<char> gorem(n);
  vector<int> goremnumber(n, 1);
  for (int i = 0; i < n; i++) {
    cin >> gorem[i];
  }
  for (int l = 0; l < 3; l++) {
    cin >> arufa >> rl;
    for (int i = 0; i < n; i++) {
      if (arufa == gorem[i]) {
        if (rl == 'R') {
          if (i == n - 1) {
            goremnumber[i] = 0;
          } else {
            goremnumber[i + 1] += goremnumber[i];
            goremnumber[i] = 0;
          }
        } else {
          if (i = 0) {
            goremnumber[i] = 0;
          } else {
            goremnumber[i - 1] += goremnumber[i];
            goremnumber[i] = 0;
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += goremnumber[i];
  }
  cout << ans << endl;
}
