  int drop_l = 0;
  ng = 'n';
  pointer = 0;
  for(int i = Q - 1; i >= 0; i--){
    if(t[i] == ng && d[i] == 'R'){
      drop_l = max(drop_l, pointer - 1);
      ng = 'n';
      pointer = 0;
    }
    if(t[i] == s[pointer] && d[i] == 'L'){
      ng = s[pointer];
      pointer++;
      if(pointer >= N){
        break;
      }
    }
  }
  drop_l = max(drop_l, pointer);

  int ans = N - (drop_r + drop_l);
  if(ans < 0){
    ans = 0;
  }

  cout << ans << endl;
}


