# translated mangooste_ok.cpp by chat GPT

import sys

input_data = sys.stdin.read().split()
it = iter(input_data)

n = int(next(it))
m = int(next(it))
path = next(it)
a = [next(it) for _ in range(n)]

x = 0
segs = [[0, 0]]

for c in path:
    if c == 'U':
        x -= 1
        segs[-1][0] = min(segs[-1][0], x)
    elif c == 'D':
        x += 1
        segs[-1][1] = max(segs[-1][1], x)
    elif c == 'R':
        segs.append([x, x])

psum = [[0] * m for _ in range(n + 1)]
for i in range(n):
    for j in range(m):
        psum[i + 1][j] = psum[i][j] + (a[i][j] == '#')

def check(col, l, r):
    if col >= m or l < 0 or r >= n:
        return False
    return psum[r + 1][col] == psum[l][col]

ans = 0
for i in range(n):
    for j in range(m):
        valid = True
        for pos, (low, high) in enumerate(segs):
            if not check(j + pos, i + low, i + high):
                valid = False
                break
        if valid:
            ans += 1

print(ans)
