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

my ($N, $Q) = split ' ', <>;
my $s = <>;
my @t;
my @d;
for (1 .. $Q) {
        my ($t, $d) = split ' ', <>;
        push @t, $t;
        push @d, $d;
}

sub simulate {
        my ($b) = @_;
        for my $i (0 .. $Q-1) {
                $b += $d[$i] eq 'L' ? -1 : 1 if (substr($s, $b, 1) eq $t[$i]);
                return -1 if ($b < 0);
                return 1 if ($b >= $N);
        }
        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;
