#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<char, char>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<P> com;
    int lpos = 0, rpos = n - 1;
    bool lf = false, rf = false;
    for (int i = 0; i < q; i++)
    {
        char t, d;
        cin >> t >> d;
        com.push_back(P(t, d));
    }
    for (int i = 0; i < q; i++)
    {
        char t = com[i].first, d = com[i].second;
        if (!lf)
        {
            if (s[lpos] == t)
            {
                if (d == 'L')
                    lpos--;
                else
                    lpos++;
                if (lpos < 0)
                    lf = true;
                if (n <= lpos)
                {
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
        if (!rf)
        {
            if (s[rpos] == t)
            {
                if (d == 'L')
                    rpos--;
                else
                    rpos++;
                if (rpos < 0)
                {
                    cout << 0 << endl;
                    return 0;
                }
                if (n <= rpos)
                    rf = true;
            }
        }
    }
    if (!lf && !rf)
    {
        cout << n << endl;
        return 0;
    }
    // 右の落ちる限界
    int rlb = n - 1, rub = -1;
    while (rlb - rub > 1)
    {
        int mid = (rlb + rub) / 2;
        bool f = false;
        int pos = mid;
        for (int i = 0; i < q; i++)
        {
            char t = com[i].first, d = com[i].second;
            if (!f)
            {
                if (s[pos] == t)
                {
                    if (d == 'L')
                        pos--;
                    else
                        pos++;
                    if (n <= pos)
                        f = true;
                }
            }
        }
        if (f)
            rlb = mid;
        else
            rub = mid;
    }
    // 左の落ちる限界
    int llb = 0, lub = n;
    while (lub - llb > 1)
    {
        int mid = (llb + lub) / 2;
        bool f = false;
        int pos = mid;
        for (int i = 0; i < q; i++)
        {
            char t = com[i].first, d = com[i].second;
            if (!f)
            {
                if (s[pos] == t)
                {
                    if (d == 'L')
                        pos--;
                    else
                        pos++;
                    if (pos < 0)
                        f = true;
                }
            }
        }
        if (f)
            llb = mid;
        else
            lub = mid;
    }
    if (!lf)
    {
        cout << rlb << endl;
        return 0;
    }
    if (!rf)
    {
        cout << n - 1 - llb << endl;
        return 0;
    }
    cout << max(0, rlb - llb - 1) << endl;
}


Measured memory_bytes: 1100