#include <bits/stdc++.h>
using namespace std;
bitset<25000> now, ul, dl, ll, rl;
int n, m, k, endx, endy;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  char c;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      while ((c = getchar()) != '#' && c != '.' && c != 'E')
        ;
      if (c == '#') {
        now[i * m + j] = 0;
        if (i != 0 && now[(i - 1) * m + j] == 1) dl[(i - 1) * m + j] = 1;
        if (j != 0 && now[i * m + j - 1] == 1) rl[i * m + j - 1] = 1;
      } else {
        now[i * m + j] = 1;
        if (i != 0 && now[(i - 1) * m + j] == 0) ul[i * m + j] = 1;
        if (j != 0 && now[i * m + j - 1] == 0) ll[i * m + j] = 1;
        if (c == 'E') {
          endx = i;
          endy = j;
        }
      }
    }
  if (now.count() == 1 && now[endx * m + endy] == 1) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < k; i++) {
    while ((c = getchar()) != 'U' && c != 'D' && c != 'L' && c != 'R')
      ;
    if (c == 'U') now = (now & ul) | ((now ^ (now & ul)) >> m);
    if (c == 'D') now = (now & dl) | ((now ^ (now & dl)) << m);
    if (c == 'L') now = (now & ll) | ((now ^ (now & ll)) >> 1);
    if (c == 'R') now = (now & rl) | ((now ^ (now & rl)) << 1);
    if (now.count() == 1 && now[endx * m + endy] == 1) {
      printf("%d\n", i + 1);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
