#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N >> Q;
  string s, L;
  cin >> s;
  char td[Q][2];
  for (int i = 0; i < Q; ++i) {
    cin >> td[i][0] >> td[i][1];
  }
  int golems[N];
  L = "76";
  for (int i = 0; i < N; ++i) {
    golems[i] = 1;
  }
  for (int i = 0; i < Q; ++i) {
    if (std::to_string(td[i][1]) == "76") {
      for (int j = 0; j < N; ++j) {
        if ((s[j] == td[i][0]) && (golems[j] > 0)) {
          if (j != 0) {
            golems[j - 1] += golems[j];
          }
          golems[j] = 0;
        }
      }
    } else {
      for (int j = 0; j < N; ++j) {
        int k;
        k = N - j - 1;
        if ((s[k] == td[i][0]) && (golems[k] > 0)) {
          if (k != (N - 1)) {
            golems[k + 1] += golems[k];
          }
          golems[k] = 0;
        }
      }
    }
  }
  int y = 0;
  for (int i = 0; i < N; ++i) {
    y += golems[i];
  }
  cout << y << endl;
  return 0;
}
