#include <bits/stdc++.h>
using namespace std;
const int maxn = 25010;
inline int read() {
  int f = 0, x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return f ? -x : x;
}
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
bitset<maxn> ch, bl, cn, e;
char s1[155], s2[100050];
int n, m, k, flag;
int work() {
  bitset<maxn> ch, bl, cn, e;
  for (int i = 0; i < n; ++i) {
    scanf("%s", s1);
    for (int j = 0; j < m; ++j) {
      if (s1[j] == '#')
        bl[i * m + j] = 1;
      else {
        cn[i * m + j] = 1;
        if (s1[j] == 'E') e[i * m + j] = 1;
      }
    }
  }
  scanf("%s", s2);
  ch = cn;
  for (int i = 0; i < k; ++i) {
    if (ch == e) return i;
    if (s2[i] == 'U') ch = (((ch >> m) & cn) | ((bl << m) & ch));
    if (s2[i] == 'D') ch = (((ch << m) & cn) | ((bl >> m) & ch));
    if (s2[i] == 'L') ch = (((ch >> 1) & cn) | ((bl << 1) & ch));
    if (s2[i] == 'R') ch = (((ch << 1) & cn) | ((bl >> 1) & ch));
  }
  if (ch == e) return k;
  return -1;
}
int main() {
  while (~scanf("%d %d %d", &n, &m, &k)) {
    write(work());
    puts("");
  }
  return 0;
}
