#include <bits/stdc++.h>
typedef struct Piyo {
  int num;
  struct Piyo *next;
} piyo;
int main(void) {
  int masu[210000];
  int n, q;
  piyo(*A) = NULL, (*B) = NULL, (*C) = NULL, (*D) = NULL, (*E) = NULL,
  (*F) = NULL, (*G) = NULL, (*H) = NULL, (*I) = NULL, (*J) = NULL, (*K) = NULL,
  (*L) = NULL, (*M) = NULL, (*N) = NULL, (*O) = NULL, (*P) = NULL, (*Q) = NULL,
  (*R) = NULL, (*S) = NULL, (*T) = NULL, (*U) = NULL, (*V) = NULL, (*W) = NULL,
  (*X) = NULL, (*Y) = NULL, (*Z) = NULL;
  char temp[210000];
  scanf("%d %d", &n, &q);
  scanf("%s", temp);
  int i, j;
  for (i = 1; i <= n; i++) {
    masu[i] = 1;
    if (temp[i - 1] == 'A') {
      if (A == NULL) {
        A = (piyo *)malloc(sizeof(piyo));
        (A->num) = i;
        A->next = NULL;
      } else {
        piyo *po = A;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'B') {
      if (B == NULL) {
        B = (piyo *)malloc(sizeof(piyo));
        (B->num) = i;
        B->next = NULL;
      } else {
        piyo *po = B;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'C') {
      if (C == NULL) {
        C = (piyo *)malloc(sizeof(piyo));
        (C->num) = i;
        C->next = NULL;
      } else {
        piyo *po = C;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'D') {
      if (D == NULL) {
        D = (piyo *)malloc(sizeof(piyo));
        (D->num) = i;
        D->next = NULL;
      } else {
        piyo *po = D;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'E') {
      if (E == NULL) {
        E = (piyo *)malloc(sizeof(piyo));
        (E->num) = i;
        E->next = NULL;
      } else {
        piyo *po = E;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'F') {
      if (F == NULL) {
        F = (piyo *)malloc(sizeof(piyo));
        (F->num) = i;
        F->next = NULL;
      } else {
        piyo *po = F;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'G') {
      if (G == NULL) {
        G = (piyo *)malloc(sizeof(piyo));
        (G->num) = i;
        G->next = NULL;
      } else {
        piyo *po = G;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'H') {
      if (H == NULL) {
        H = (piyo *)malloc(sizeof(piyo));
        (H->num) = i;
        H->next = NULL;
      } else {
        piyo *po = H;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'I') {
      if (I == NULL) {
        I = (piyo *)malloc(sizeof(piyo));
        (I->num) = i;
        I->next = NULL;
      } else {
        piyo *po = I;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'J') {
      if (J == NULL) {
        J = (piyo *)malloc(sizeof(piyo));
        (J->num) = i;
        J->next = NULL;
      } else {
        piyo *po = J;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'K') {
      if (K == NULL) {
        K = (piyo *)malloc(sizeof(piyo));
        (K->num) = i;
        K->next = NULL;
      } else {
        piyo *po = K;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'L') {
      if (L == NULL) {
        L = (piyo *)malloc(sizeof(piyo));
        (L->num) = i;
        L->next = NULL;
      } else {
        piyo *po = L;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'M') {
      if (M == NULL) {
        M = (piyo *)malloc(sizeof(piyo));
        (M->num) = i;
        M->next = NULL;
      } else {
        piyo *po = M;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'N') {
      if (N == NULL) {
        N = (piyo *)malloc(sizeof(piyo));
        (N->num) = i;
        N->next = NULL;
      } else {
        piyo *po = N;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'O') {
      if (O == NULL) {
        O = (piyo *)malloc(sizeof(piyo));
        (O->num) = i;
        O->next = NULL;
      } else {
        piyo *po = O;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'P') {
      if (P == NULL) {
        P = (piyo *)malloc(sizeof(piyo));
        (P->num) = i;
        P->next = NULL;
      } else {
        piyo *po = P;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'Q') {
      if (Q == NULL) {
        Q = (piyo *)malloc(sizeof(piyo));
        (Q->num) = i;
        Q->next = NULL;
      } else {
        piyo *po = Q;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'R') {
      if (R == NULL) {
        R = (piyo *)malloc(sizeof(piyo));
        (R->num) = i;
        R->next = NULL;
      } else {
        piyo *po = R;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'S') {
      if (S == NULL) {
        S = (piyo *)malloc(sizeof(piyo));
        (S->num) = i;
        S->next = NULL;
      } else {
        piyo *po = S;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'T') {
      if (T == NULL) {
        T = (piyo *)malloc(sizeof(piyo));
        (T->num) = i;
        T->next = NULL;
      } else {
        piyo *po = T;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'U') {
      if (U == NULL) {
        U = (piyo *)malloc(sizeof(piyo));
        (U->num) = i;
        U->next = NULL;
      } else {
        piyo *po = U;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'V') {
      if (V == NULL) {
        V = (piyo *)malloc(sizeof(piyo));
        (V->num) = i;
        V->next = NULL;
      } else {
        piyo *po = V;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'W') {
      if (W == NULL) {
        W = (piyo *)malloc(sizeof(piyo));
        (W->num) = i;
        W->next = NULL;
      } else {
        piyo *po = W;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'X') {
      if (X == NULL) {
        X = (piyo *)malloc(sizeof(piyo));
        (X->num) = i;
        X->next = NULL;
      } else {
        piyo *po = X;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'Y') {
      if (Y == NULL) {
        Y = (piyo *)malloc(sizeof(piyo));
        (Y->num) = i;
        Y->next = NULL;
      } else {
        piyo *po = Y;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    } else if (temp[i - 1] == 'Z') {
      if (Z == NULL) {
        Z = (piyo *)malloc(sizeof(piyo));
        (Z->num) = i;
        Z->next = NULL;
      } else {
        piyo *po = Z;
        while ((po->next) != NULL) po = (po->next);
        (po->next) = (piyo *)malloc(sizeof(piyo));
        (po->next->num) = i;
        po->next->next = NULL;
      }
    }
  }
  for (i = 0; i < q; i++) {
    char t[5], d[5];
    piyo *p;
    scanf("%s %s", t, d);
    if (t[0] == 'A') {
      p = A;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'B') {
      p = B;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'C') {
      p = C;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'D') {
      p = D;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'E') {
      p = E;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'F') {
      p = F;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'G') {
      p = G;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'H') {
      p = H;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'I') {
      p = I;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'J') {
      p = J;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'K') {
      p = K;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'L') {
      p = L;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'M') {
      p = M;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'N') {
      p = N;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'O') {
      p = O;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'P') {
      p = P;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'Q') {
      p = Q;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'R') {
      p = R;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'S') {
      p = S;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'T') {
      p = T;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'U') {
      p = U;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'V') {
      p = V;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'W') {
      p = W;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'X') {
      p = X;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'Y') {
      p = Y;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    } else if (t[0] == 'Z') {
      p = Z;
      while (p != NULL) {
        if (d[0] == 'L') {
          masu[(p->num) - 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        } else {
          masu[(p->num) + 1] += masu[(p->num)];
          masu[(p->num)] = 0;
        }
        p = (p->next);
      }
    }
  }
  int ans = 0;
  for (i = 1; i <= n; i++) {
    ans += masu[i];
  }
  printf("%d\n", ans);
  return 0;
}
