#include <bits/stdc++.h>
using namespace std;
void fre() {
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
}
void fc() {
  fclose(stdin);
  fclose(stdout);
}
inline long long ccin() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
inline void cou(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) cou(x / 10);
  putchar(x % 10 + '0');
}
const int maxn = 2e3 + 10;
const long long inf = 0x7fffffff;
bitset<23000> tu, all, mo;
int n, m, x1, x2, ans, k;
string dema;
int main() {
  n = ccin();
  m = ccin();
  k = ccin();
  for (int i = 0; i < n; i++) {
    string k1;
    cin >> k1;
    for (int j = 0; j < m; j++) {
      char a1 = k1[j];
      if (a1 == '#') {
        tu.set(i * m + j);
      } else if (a1 == '.') {
        all.set(i * m + j);
      } else {
        mo.set(i * m + j);
        all.set(i * m + j);
      }
    }
  }
  cin >> dema;
  for (int i = 0; i < k; i++) {
    if (all == mo) {
      cout << i << '\n';
      return 0;
    }
    if (dema[i] == 'U')
      all = (all >> m) & (~tu) | ((tu << m) & all);
    else if (dema[i] == 'D')
      all = all << m & (~tu) | (all & (tu >> m));
    else if (dema[i] == 'L')
      all = all >> 1 & (~tu) | (all & (tu << 1));
    else
      all = ((tu >> 1) & (all)) | all << 1 & (~tu);
    if (all == mo) {
      cout << i + 1 << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}
