#include <bits/stdc++.h>
using namespace std;
int n, m, k, E;
int vis[155 * 155], t = 0;
bitset<155 * 155> a, b;
inline int num(int x, int y) { return (x - 1) * m + y; }
int main() {
  scanf("%d%d%d", &n, &m, &k);
  char ch;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf(" %c", &ch);
      if (ch == '#')
        b[num(i, j)] = 1;
      else
        a[num(i, j)] = 1;
      if (ch == 'E') E = num(i, j);
    }
  if (a.count() == 1) {
    printf("0");
    return 0;
  }
  for (int i = 1; i <= k; i++) {
    scanf(" %c", &ch);
    if (ch == 'U')
      a = ((a >> m) & ~b) | (((a >> m) & b) << m);
    else if (ch == 'D')
      a = ((a << m) & ~b) | (((a << m) & b) >> m);
    else if (ch == 'L')
      a = ((a >> 1) & ~b) | (((a >> 1) & b) << 1);
    else if (ch == 'R')
      a = ((a << 1) & ~b) | (((a << 1) & b) >> 1);
    if (a.count() == 1 && a[E]) {
      printf("%d", i);
      return 0;
    }
  }
  printf("-1");
  return 0;
}
