#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using u64 = unsigned long long;
using u32 = unsigned int;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, long long>;
using pli = pair<long long, int>;
using pll = pair<long long, long long>;
template <typename T>
using uset = unordered_set<T>;
template <typename T1, typename T2>
using umap = unordered_map<T1, T2>;

template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

#ifndef _DEBUG
#pragma GCC optimize("O3,unroll-loops,fast-math")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif

inline void solve() {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    vector<string> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector nxt(n, vector<int>(m));
    for (int i = n - 1; i > -1; i--)
        for (int j = 0; j < m; j++)
            nxt[i][j] = a[i][j] == '#' ? i : (i == n - 1 ? n : nxt[i + 1][j]);
    vector<pii> segments;
    int l = 0, r = 0;
    int x = 0;
    segments.push_back(pii(0, 0));
    for (char c : s) {
        if (c == 'R') {
            l = r = x;
            segments.push_back({l, r});
        } else {
            if (c == 'D')
                x++;
            else
                x--;
            l = min(l, x);
            r = max(r, x);
            segments.back() = {l, r};
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (j + segments.size() <= m) {
                bool good = true;
                for (int c = 0; c < (int)segments.size(); c++) {
                    auto [L, R] = segments[c];
                    if (i + L < 0 || i + L >= n || nxt[i + L][j + c] <= i + R)
                        good = false;
                }
                if (good)
                    ans++;
            }
    cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
    freopen("01.dat", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tt = 1;
#ifdef _DEBUG
    cin >> tt;
#endif
    for (int test_id = 1; test_id <= tt; test_id++) {
#ifdef _DEBUG
        cout << "Case #" << test_id << ":\n";
#endif
        solve();
    }
    return 0;
}
