#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 ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            bool valid = true;
            int x = i, y = j;
            for (auto c : path) {
                if (c == 'U') {
                    x--;
                } else if (c == 'D') {
                    x++;
                } else {
                    y++;
                }
                if (x < 0 || x >= n || y >= m || a[x][y] == '#') {
                    valid = false;
                    break;
                }
            }
            ans += valid;
        }
    }
    cout << ans << '\n';
}
