#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
map<char,set<int>> M;
string S;
struct Union_Find{
  vi par;
  Union_Find(int N):par(N){
    rep(i,0,N) par[i]=i;
  }
  int root(int X){
    if(par[X]==X||par[X]==-1||par[X]==N) return par[X];
    return par[X]=root(par[X]);
  }
  void insert(int X,int Y){
    if(Y==-1){
      par[X]=-1;
      M[S[X]].erase(X);
    }
    else if(Y==N){
      par[X]=N;
      M[S[X]].erase(X);
    }
    else{
      par[X]=Y;
      M[S[Y]].insert(Y);
      M[S[X]].erase(X);
    }
  }
  bool safe(int X){
    if(root(X)==-1||root(X)==N) return 0;
    return 1;
  }
};
signed main(){
  int N,Q;
  cin>>S;
  rep(i,0,N) M[S[i]].insert(i);
  Union_Find tree(N);
  rep(i,0,Q){
    char A,B; cin>>A>>B;
    int X=1;
    if(B=='L') X=-1;
    for(auto p:M[A]){
      tree.insert(p,p+X);
    }
  }
  int ans=0;
  rep(i,0,N){
    if(safe(i)) ans++;
  }
  cout<<ans<<endl;
  }
