using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		// *AABCBDBA*
		// 0111111110
		// 1101111200 A L
		// 0100202020 B R
		// 1010202002 A R
		// 1000000001
		// 1000000011 A L
		// 1000000111 B L
		// 1100000111 A R
		// *ABC*
		// 10001
		// 11001
		var I = G;
		int N = I[0], Q = I[1];
		var S = Str.Select(c => c - 'A').ToArray();
		var qs = new Pair[Q];
		for (var i = 0; i < Q; i++)
		{
			var q = Strs;
			qs[i] = new Pair(q[0][0] - 'A', q[1] == "L" ? -1 : 1);
		}
		var j = FirstBinary(-1, N, x =>
		{
			if (x < 0) return false;
			if (x >= N) return true;
			foreach (var q in qs)
			{
				if (q.C == S[x])
				{
					x += q.D;
					if (x < 0) return false;
					if (x >= N) return true;
				}
			}
			return true;
		});
		// WriteLine(j);
		var k = FirstBinary(j, N, x =>
		{
			if (x < 0) return false;
			if (x >= N) return true;
			foreach (var q in qs)
			{
				if (q.C == S[x])
				{
					x += q.D;
					if (x < 0) return false;
					if (x >= N) return true;
				}
			}
			return false;
		});
		// WriteLine(k);
		WriteLine(k - j);
	}
	public static int FirstBinary(int min, int max, Predicate<int> pred)
	{
		while (min < max)
		{
			var mid = (min + max) / 2;
			if (pred(mid)) max = mid;
			else min = mid + 1;
		}
		return min;
	}
}
struct Pair
{
	public int C, D;
	public Pair(int c, int d) { C = c; D = d; }
}