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