#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int i, j, k, N, Q;
  char s[200002];
  char t, d;
  cin >> N >> Q;
  cin >> s;
  int *data = new int[N + 2];
  for (i = 1; i <= N; i++) {
    data[i] = 1;
  }
  data[0] = data[N + 1] = 0;
  vector<vector<int> > table;
  int tablecnt[26];
  for (i = 0; i < 26; i++) tablecnt[i] = 0;
  table.resize(26);
  for (i = 0; i < N; i++) {
    int tmp = s[i] - 'A';
    table[tmp].push_back(i);
    tablecnt[tmp]++;
  }
  for (i = 0; i < Q; i++) {
    cin >> t >> d;
  }
  cout << N - data[0] - data[N + 1] << endl;
  delete[] data;
  return 0;
}
