#include <bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const int maxn = 1e6+7;
ll n,m,ans=1,pre[maxn],a,b;
map<pair<ll,ll>,ll> mp;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    freopen("ROBOT.INP","r",stdin);
    freopen("ROBOT.OUT","w",stdout);
    cin >> n >> m;
    string s,t; cin >> s >> t;
    ll x=1,y=1;
    mp[{x,y}] = 1;
    mp[{n,m}] = 1;
    for (auto c:s)
    {
        if (c == 'D')
        {
            x++;
            mp[{x,y}] = 1;
        }
        else if (c == 'R')
        {
            y++;
            mp[{x,y}] = 1;
        }
    }
    x = n, y = m;
    for (auto c:t)
    {
        if (c == 'U')
        {
            x--;
            if (mp[{x,y}] == 1) ans++;
        }
        else if (c == 'L')
        {
            y--;
            if (mp[{x,y}] == 1) ans++;
        }
        // cout << ans << '\n';
    }

    cout << ans;
    return 0;
}
