#include <bits/stdc++.h>
using namespace std;
int n, m;
int k;
bool debug = false;
bitset<22600> init, wall, E, pos;
char s[100005];
int main() {
  scanf("%d%d%d", &n, &m, &k);
  int idx = 0;
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    for (int j = 0; j < m; j++) {
      if (s[j] == '#')
        wall[idx] = 1;
      else {
        init[idx] = 1;
        if (s[j] == 'E') E[idx] = 1;
      }
      idx++;
    }
  }
  pos = init;
  if (pos == E) {
    puts("0");
    return 0;
  }
  scanf("%s", s);
  int ans = -1;
  for (int i = 0; i < k; i++) {
    if (s[i] == 'U') pos = ((wall << m) & pos) | ((pos >> m) & init);
    if (s[i] == 'D') pos = ((wall >> m) & pos) | ((pos << m) & init);
    if (s[i] == 'L') pos = ((wall << 1) & pos) | ((pos >> 1) & init);
    if (s[i] == 'R') pos = ((wall >> 1) & pos) | ((pos << 1) & init);
    if (pos == E) {
      ans = i + 1;
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}
