use v5.18;
use POSIX qw(floor ceil);

my ($N, $Q) = split ' ', <>;
my $s = <>;
my @t = ();
my @d = ();
for my $i (1 .. $Q) {
        my ($t, $d) = split ' ', <>;
        $t[$i] = $t;
        $d[$i] = ($d eq 'L') ? -1 : 1;
}
my @s = ();
for my $i (0 .. $N-1) {
        $s[$i] = substr($s, $i, 1);
}

sub simulate {
        my ($b) = @_;
        my $sb = $s[$b];
        my $i;
        for $i (1 .. $Q) {
                if ($sb eq $t[$i]) {
                        $b += $d[$i];
                        return -1 if ($b < 0);
                        return 1 if ($b >= $N);
                        $sb = $s[$b];
                }
        }
        return 0;
}

my $a = 0;
my $b;
my $b_prev = -1;
my $c = $N - 1;
while (1) {
        $b = floor(($a + $c) / 2);
        last if ($b == $b_prev);
        if (simulate($b) < 0) {
                $a = $b;
        } else {
                $c = $b;
        }
        $b_prev = $b;
}
my $l = $a;

my $a = 0;
my $b;
my $b_prev = -1;
my $c = $N - 1;
while (1) {
        $b = ceil(($a + $c) / 2);
        last if ($b == $b_prev);
        if (simulate($b) > 0) {
                $c = $b;
        } else {
                $a = $b;
        }
        $b_prev = $b;
}
my $r = $a;

say $r - $l;
