fun rec(s: String, input: Array<Array<String>>, pos: Int): Int {
	var p = pos
	for (i in input) {
		if (s[p] == i[0][0]) p += if (i[1][0] == 'L') -1 else 1
		if (p < 0 || p >= s.length) return p
	}
	return p
}

fun main(args: Array<String>) {
	val (n, q) = (readLine() ?: return).split(" ").map { it.toInt() }
	val s = readLine() ?: return

	val input = Array(q) { (readLine() ?: return).split(" ").toTypedArray() }

	val left = rec(s, input, 0)
	val right = rec(s, input, n - 1)
	if (left == right) {
		println(0)
		return
	}

	val leftP = when {
		left >= 0 -> 0
		else -> {
			var l = 0
			var r = n - 1
			while (l + 1 < r) {
				val m = l + (r - l) / 2
				val mid = rec(s, input, m)
				if (mid < 0) l = m
				else r = m
			}
			r
		}
	}
	val rightP = when {
		right <= n-1 -> n-1
		else -> {
			var l = 0
			var r = n - 1
			while (l + 1 < r) {
				val m = l + (r - l) / 2
				val mid = rec(s, input, m)
				if (mid > n-1) r = m
				else l = m
			}
			l
		}
	}
	println(rightP-leftP+1)
}