#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m, k;
bitset<151> f[151], w[151], fn[151], cur[151];
string g[151];
string s;
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) cin >> g[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (g[i][j] == '#')
        w[i][j] = 1;
      else {
        f[i][j] = 1;
        if (g[i][j] == 'E') fn[i][j] = 1;
      }
  for (int i = 0; i < n; i++) cur[i] = f[i];
  cin >> s;
  int ok = 1;
  for (int i = 0; i < n; i++)
    if (cur[i] != fn[i]) ok = 0;
  if (ok) {
    printf("%d\n", 0);
    return 0;
  }
  for (int it = 0; it < k; it++) {
    if (s[it] == 'L')
      for (int i = 0; i < n; i++)
        cur[i] = ((cur[i] >> 1) & f[i]) | (((cur[i] >> 1) & w[i]) << 1);
    if (s[it] == 'R')
      for (int i = 0; i < n; i++)
        cur[i] = ((cur[i] << 1) & f[i]) | (((cur[i] << 1) & w[i]) >> 1);
    if (s[it] == 'U')
      for (int i = 1; i + 1 < n; i++)
        cur[i] = (cur[i + 1] & f[i]) | (cur[i] & w[i - 1]);
    if (s[it] == 'D')
      for (int i = n - 2; i > 0; i--)
        cur[i] = (cur[i - 1] & f[i]) | (cur[i] & w[i + 1]);
    int ok = 1;
    for (int i = 0; i < n; i++)
      if (cur[i] != fn[i]) ok = 0;
    if (ok) {
      printf("%d\n", it + 1);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
