#include <bits/stdc++.h>
std::bitset<23000> a, b, c, e;
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  getchar();
  for (int i = 0; i < n; i++, getchar())
    for (int j = 0; j < m; j++) {
      char s = getchar();
      (s == '#' ? b : a).set(i * m + j);
      (s == 'E' ? e.set(i * m + j) : 0);
    }
  c = a;
  for (int i = 0; i < k; i++) {
    char s = getchar();
    if (c == e) {
      printf("%d\n", i);
      return 0;
    }
    if (s == 'U') c = ((c >> m) & a) | (c & (b << m));
    if (s == 'L') c = ((c >> 1) & a) | (c & (b << 1));
    if (s == 'D') c = ((c << m) & a) | (c & (b >> m));
    if (s == 'R') c = ((c << 1) & a) | (c & (b >> 1));
  }
  if (c == e)
    printf("%d\n", k);
  else
    printf("%d\n", -1);
  return 0;
}
