import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.format;

void main() {
  int n, q;
  string s;
  s = readln;
  formattedRead (s, " %d %d", &n, &q);
  s = readln;
  auto label = new char[q];
  auto go = new char[q];

  foreach (qid; 0 .. q) {
    string z = readln;
    auto spl = z.splitter.array;
    label[qid] = spl[0][0];
    go[qid] = spl[1][0];
  }

  bool checkL (int x) {
    if (x == 0) return true;
    if (x > n) return false;
    foreach (qid; 0 .. q) {
      if (s[x-1] == label[qid]) {
        if (go[qid] == 'L') { if (--x < 1) return true; }
        else if (++x > n) return false;
      }
    }
    return false;
  }
  
  bool checkR (int x) {
    debug stderr.writefln ("checkR %d\n", x);
    if (x == 0) return false;
    if (x > n) return true;
    foreach (qid; 0 .. q) {
      if (s[x-1] == label[qid]) {
        if (go[qid] == 'L') { if (--x < 1) return false; }
        else if (++x > n) return true;
      }
    }
    return false;
  }
  
  //[l, r)
  int l = 0, r = n + 1;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    bool ch = checkL (m);
    debug stderr.writefln ("check(%d) = %s", m, ch);
    if (ch) l = m; else r = m;
  }
  immutable x1 = l + 1; 
  debug stderr.writefln ("x1 = %d", x1);
  
  l = 0; r = n + 1;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    bool ch = checkR (m);
    debug stderr.writefln ("checkR(%d) = %s", m, ch);
    if (!ch) l = m; else r = m;
  }
  immutable x2 = l + 1;
  debug stderr.writefln ("x2 = %d", x2);
  writeln (max (0, abs (x2 - x1)));
}

