#include <bits/stdc++.h>
using namespace std;
const int N = 155, M = 100005;
int n, m, k, goal, tot;
char st[N][N], qs[M];
bitset<N * N> now, up, down, le, ri;
void UP() { now = ((now & up) >> m) | (now & up ^ now); }
void DOWN() { now = ((now & down) << m) | (now & down ^ now); }
void LEFT() { now = ((now & le) >> 1) | (now & le ^ now); }
void RIGHT() { now = ((now & ri) << 1) | (now & ri ^ now); }
int main() {
  cin >> n >> m >> k;
  now.reset(), up.reset(), down.reset(), le.reset(), ri.reset();
  for (int i = 0; i < n; i++) scanf("%s", st[i]);
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      if (st[i][j] == '.' || st[i][j] == 'E') {
        if (st[i][j] == 'E') goal = i * m + j;
        tot++, now[i * m + j] = 1;
        if (st[i - 1][j] == '.' || st[i - 1][j] == 'E') up[i * m + j] = 1;
        if (st[i + 1][j] == '.' || st[i + 1][j] == 'E') down[i * m + j] = 1;
        if (st[i][j - 1] == '.' || st[i][j - 1] == 'E') le[i * m + j] = 1;
        if (st[i][j + 1] == '.' || st[i][j + 1] == 'E') ri[i * m + j] = 1;
      }
    }
  }
  if (tot == 1) {
    puts("0");
    return 0;
  }
  scanf("%s", qs + 1);
  for (int i = 1; i <= k; i++) {
    if (qs[i] == 'U') UP();
    if (qs[i] == 'D') DOWN();
    if (qs[i] == 'L') LEFT();
    if (qs[i] == 'R') RIGHT();
    if (now.count() == 1 && now[goal] == 1) {
      printf("%d\n", i);
      return 0;
    }
  }
  puts("-1");
  return 0;
}
