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