#include <bits/stdc++.h>
using namespace std;
const int N = 153, M = 1e5 + 7;
int n, m, K, ed;
char s[M];
bitset<N * N> wall, now, can;
int main() {
  scanf("%d%d%d", &n, &m, &K);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; j++) {
      if (s[j] == '#')
        wall[i * m + j] = 1;
      else
        can[i * m + j] = now[i * m + j] = 1;
      if (s[j] == 'E') ed = i * m + j;
    }
  }
  scanf("%s", s + 1);
  if (now.count() == 1 && now[ed]) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= K; i++) {
    if (s[i] == 'U')
      now = (now >> m & can) | (now & (wall << m));
    else if (s[i] == 'D')
      now = (now << m & can) | (now & (wall >> m));
    else if (s[i] == 'L')
      now = (now >> 1 & can) | (now & (wall << 1));
    else
      now = (now << 1 & can) | (now & (wall >> 1));
    if (now.count() == 1 && now[ed]) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
