#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int n, m;
    string path;
    cin >> n >> m >> path;
    vector<string> a(n);
    for (auto &s : a) {
        cin >> s;
    }

    int x = 0;
    vector<pair<int, int>> segs = {{0, 0}};

    for (auto c : path) {
        if (c == 'U') {
            x--;
            segs.back().first = min(segs.back().first, x);
        } else if (c == 'D') {
            x++;
            segs.back().second = max(segs.back().second, x);
        } else if (c == 'R') {
            segs.emplace_back(x, x);
        } else {
            assert(false);
        }
    }

    vector psum(n + 1, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            psum[i + 1][j] = psum[i][j] + (a[i][j] == '#');
        }
    }

    auto check = [&](int col, int l, int r) {
        if (col >= m || l < 0 || r >= n) {
            return false;
        }
        return psum[r + 1][col] == psum[l][col];
    };

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            bool valid = true;
            for (int pos = 0; pos < (int)segs.size(); pos++) {
                if (!check(j + pos, i + segs[pos].first, i + segs[pos].second)) {
                    valid = false;
                    break;
                }
            }
            ans += valid;
        }
    }
    cout << ans << '\n';
}
