#include <bits/stdc++.h>

using namespace std;
#define int long long

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, m;
    string s;
    cin >> n >> m >> s;
    vector<vector<char>> field(n, vector<char>(m));
    vector<vector<int>> pref(n, vector<int>(m + 1));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> field[i][j];
            pref[i][j + 1] = pref[i][j] + (field[i][j] == '#');
        }
    }
    pair<int, int> dx = {0, 0};
    pair<int, int> dy = {0, 0};
    {
        int x = 0;
        int y = 0;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == 'D') {
                x++;
            } else if (s[i] == 'U') {
                x--;
            } else if (s[i] == 'R') {
                y++;
            }
            dx.first = min(dx.first, x);
            dx.second = max(dx.second, x);
            dy.first = min(dy.first, y);
            dy.second = max(dy.second, y);
        }
    }
    auto check = [&](int x, int y) -> bool {
        if (field[x][y] == '#' || x + dx.first < 0 || x + dx.second >= n || y + dy.first < 0 || y + dy.second >= m) {
            return false;
        }
        int cnt = 0;
        for (int i = x + dx.first; i <= x + dx.second; i++) {
            cnt += pref[i][y + dy.second + 1] - pref[i][y + dy.first];
        }
        if (cnt == 0) {
            return true;
        }
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == 'D') {
                x++;
            } else if (s[i] == 'U') {
                x--;
            } else if (s[i] == 'R') {
                y++;
            }
            if (x < 0 || x >= n || y >= m || field[x][y] == '#') {
                return false;
            }
        }
        return true;
    };
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans += check(i, j);
        }
    }
    cout << ans;
}
