#include <bits/stdc++.h>
using namespace std;
int n, m, len;
char A[155][155], st[100005];
bitset<155 * 155> bar, U, D, L, R, E, F, G, End;
int gd(int x, int y) { return (x - 1) * m + y; }
int main() {
  int i, j;
  scanf("%d %d %d\n", &n, &m, &len);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) A[i][j] = getchar();
    getchar();
  }
  for (i = 1; i <= len; i++) st[i] = getchar();
  for (i = 2; i < n; i++)
    for (j = 2; j < m; j++) {
      if (A[i + 1][j] == '#') D[gd(i, j)] = 1;
      if (A[i - 1][j] == '#') U[gd(i, j)] = 1;
      if (A[i][j + 1] == '#') R[gd(i, j)] = 1;
      if (A[i][j - 1] == '#') L[gd(i, j)] = 1;
      if (A[i][j] != '#') bar[gd(i, j)] = 1;
      if (A[i][j] == 'E') End[gd(i, j)] = 1;
    }
  for (i = 1; i <= len + 1; i++) {
    if (bar == End) {
      printf("%d", i - 1);
      return 0;
    }
    if (st[i] == 'U') {
      E = bar & U;
      bar = ((bar ^ E) >> m) | E;
    }
    if (st[i] == 'D') {
      E = bar & D;
      bar = ((bar ^ E) << m) | E;
    }
    if (st[i] == 'L') {
      E = bar & L;
      bar = ((bar ^ E) >> 1) | E;
    }
    if (st[i] == 'R') {
      E = bar & R;
      bar = ((bar ^ E) << 1) | E;
    }
  }
  printf("-1");
  return 0;
}
