Problem: Given a string of length n s = s1, s2,…, sn and m queries. Each query qk (1 ≤ k ≤ m) is one of four types, "L ++", "L-", "R ++", "R-", and l [for the kth query qk. k] and r [k] are defined below.

* L ++: l [k] = l [k-1] + 1, r [k] = r [k-1]

* L-: l [k] = l [k-1] -1, r [k] = r [k-1]

* R ++: l [k] = l [k-1], r [k] = r [k-1] +1

* R-: l [k] = l [k-1], r [k] = r [k-1] -1




However, l [0] = r [0] = 1.

At this time, how many kinds of character strings are created for m substrings sl [k], sl [k] + 1,…, sr [k] -1, sr [k] (1 ≤ k ≤ m). Answer if you can.

Constraints

* The string s consists of a lowercase alphabet

* 1 ≤ n ≤ 3 x 105

* 1 ≤ m ≤ 3 × 105

* qk (1 ≤ k ≤ m) is one of "L ++", "L-", "R ++", "R-"

* 1 ≤ l [k] ≤ r [k] ≤ n (1 ≤ k ≤ m)

Input

Input is given in the following format

> n m
> s
> q1
> q2
>…
> qm
>

Output

Output the solution of the problem on one line

Examples

Input

5 4
abcde
R++
R++
L++
L--


Output

3


Input

4 6
abab
R++
L++
R++
L++
R++
L++


Output

4


Input

10 13
aacacbabac
R++
R++
L++
R++
R++
L++
L++
R++
R++
L--
L--
R--
R--


Output

11

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

struct RollingHash{ //ローリングハッシュ法
private:
    const int mod1 = 1031326447, mod2 = 993766717;
    const int base1 = 281, base2 = 383;
    vector<int> hash1, hash2, pow1, pow2;
public:
    string str;
    RollingHash(const string& s) : str(s) { //初期化
        int sz = (int)s.size();
        hash1 = hash2 = vector<int>(sz + 1, 0);
        pow1 = pow2 = vector<int>(sz + 1, 1);
        rep(i, sz){
            hash1[i + 1] = (hash1[i] * base1 + s[i]) % mod1;
            hash2[i + 1] = (hash2[i] * base2 + s[i]) % mod2;
            pow1[i + 1] = pow1[i] * base1 % mod1;
            pow2[i + 1] = pow2[i] * base2 % mod2;
        }
    }
    inline pair<int, int> get(int l, int r){ //[l, r)
        int res1 = ((hash1[r] - hash1[l] * pow1[r - l]) % mod1 + mod1) % mod1;
        int res2 = ((hash2[r] - hash2[l] * pow2[r - l]) % mod2 + mod2) % mod2;
        return pair<int, int>(res1, res2);
    }
    inline void add_str(const string& s){ //string型を連結
        int ns = (int)str.size(), ms = (int)s.size();
        str += s;
        hash1.resize(ns + ms + 1); hash2.resize(ns + ms + 1);
        pow1.resize(ns + ms + 1); pow2.resize(ns + ms + 1);
        for(int i = ns; i < ns + ms; i++){
            hash1[i + 1] = (hash1[i] * base1 + s[i - ns]) % mod1;
            hash2[i + 1] = (hash2[i] * base2 + s[i - ns]) % mod2;
            pow1[i + 1] = pow1[i] * base1 % mod1;
            pow2[i + 1] = pow2[i] * base2 % mod2;
        }
    }
    inline void add_char(const char& c){ //char型を連結
        str += c;
        hash1.push_back((hash1.back() * base1 + c) % mod1);
        hash2.push_back((hash2.back() * base2 + c) % mod2);
        pow1.push_back((pow1.back() * base1) % mod1);
        pow2.push_back((pow2.back() * base2) % mod2);
    }
    inline void add_rh(const RollingHash& rh){ //rhを連結
        add_str(rh.str);
    }
    inline size_t size(){ //strのsizeを返す
        return str.size();
    }
};

signed main(void){

    int N, M;
    string S;
    cin >> N >> M >> S;

    RollingHash rh(S);
    set<pair<int, int>> st;

    int l = 0, r = 1;
    rep(loop, M){
        string q; cin >> q;
        if(q == "L++")l++;
        if(q == "L--")l--;
        if(q == "R++")r++;
        if(q == "R--")r--;
        st.insert(rh.get(l, r));
    }

    cout << st.size() << endl;
    return 0;

}