#include <bits/stdc++.h>
using namespace std;
const int NR = 160, MR = 1e5 + 10;
int n, m, len;
char c[NR][NR], s[MR];
int x_end, y_end;
bitset<NR * NR> now, flag;
int id(int x, int y) { return n * m - ((x - 1) * m + y) + 1; }
void change(char face) {
  if (face == 'U') now = ((now << m) & ~flag) | (((now << m) & flag) >> m);
  if (face == 'D') now = ((now >> m) & ~flag) | (((now >> m) & flag) << m);
  if (face == 'L') now = ((now << 1) & ~flag) | (((now << 1) & flag) >> 1);
  if (face == 'R') now = ((now >> 1) & ~flag) | (((now >> 1) & flag) << 1);
}
int main() {
  scanf("%d%d%d", &n, &m, &len);
  for (int i = 1; i <= n; i++) scanf("%s", c[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (c[i][j] == '#')
        flag[id(i, j)] = 1;
      else
        now[id(i, j)] = 1;
      if (c[i][j] == 'E') x_end = i, y_end = j;
    }
  scanf("%s", s + 1);
  if (now.count() == 1 && now[id(x_end, y_end)]) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= len; i++) {
    change(s[i]);
    if (now.count() == 1 && now[id(x_end, y_end)]) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
