#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 998244353;
const ll INF = 1e18;
int main() {
  ll N, Q, ans = 0;
  string S;
  cin >> N >> Q >> S;
  vector<char> t(Q), d(Q);
  for (long long i = 0; i < (Q); ++i) {
    cin >> t.at(i) >> d.at(i);
  }
  ll v = (ll)pow(2, 17);
  for (long long i = 0; i < (17); ++i) {
    if (v >= N) {
      v -= (ll)pow(2, 16 - i);
      continue;
    }
    ll k = v;
    for (long long j = 0; j < (Q); ++j) {
      if (k == -1 || k == N) {
        break;
      }
      if (S.at(k) == t.at(j)) {
        if (d.at(j) == 'L') {
          k--;
        } else {
          k++;
        }
      }
    }
    if (k == -1) {
      v += (ll)pow(2, 16 - i);
    } else {
      v -= (ll)pow(2, 16 - i);
    }
    if (i == 16) {
      if (v >= N) {
        v -= (ll)pow(2, 16 - i);
      }
      ll k = v;
      for (long long j = 0; j < (Q); ++j) {
        if (k == -1 || k == N) {
          break;
        }
        if (S.at(k) == t.at(j)) {
          if (d.at(j) == 'L') {
            k--;
          } else {
            k++;
          }
        }
      }
      if (k != -1) {
        v -= (ll)pow(2, 16 - i);
      }
      if (v >= N) {
        v -= (ll)pow(2, 16 - i);
      }
      k = v;
      for (long long j = 0; j < (Q); ++j) {
        if (k == -1 || k == N) {
          break;
        }
        if (S.at(k) == t.at(j)) {
          if (d.at(j) == 'L') {
            k--;
          } else {
            k++;
          }
        }
      }
      if (k != -1) {
        v -= (ll)pow(2, 16 - i);
      }
    }
  }
  ans += v + 1;
  v = (ll)pow(2, 17);
  for (long long i = 0; i < (17); ++i) {
    if (v >= N) {
      v -= (ll)pow(2, 16 - i);
      continue;
    }
    ll k = v;
    for (long long j = 0; j < (Q); ++j) {
      if (k == -1 || k == N) {
        break;
      }
      if (S.at(k) == t.at(j)) {
        if (d.at(j) == 'L') {
          k--;
        } else {
          k++;
        }
      }
    }
    if (k == N) {
      v -= (ll)pow(2, 16 - i);
    } else {
      v += (ll)pow(2, 16 - i);
    }
    if (i == 16) {
      if (v == N) {
        break;
      }
      ll k = v;
      for (long long j = 0; j < (Q); ++j) {
        if (k == -1 || k == N) {
          break;
        }
        if (S.at(k) == t.at(j)) {
          if (d.at(j) == 'L') {
            k--;
          } else {
            k++;
          }
        }
      }
      if (k != N) {
        v += (ll)pow(2, 16 - i);
      }
      if (v == N) {
        break;
      }
      k = v;
      for (long long j = 0; j < (Q); ++j) {
        if (k == -1 || k == N) {
          break;
        }
        if (S.at(k) == t.at(j)) {
          if (d.at(j) == 'L') {
            k--;
          } else {
            k++;
          }
        }
      }
      if (k != N) {
        v += (ll)pow(2, 16 - i);
      }
    }
  }
  cout << N - (ans + (N - v)) << endl;
}
