#include <bits/stdc++.h>
using namespace std;
int n, m, k, p[200][200];
bitset<40000> a, c, b, e;
char ch[100009];
int work() {
  for (int i = 0; i < n; i++) {
    scanf("%s", ch);
    for (int j = 0; j < m; j++) {
      if (ch[j] == '#')
        b[i * m + j] = 1;
      else
        a[i * m + j] = 1;
      if (ch[j] == 'E') e[i * m + j] = 1;
    }
  }
  cin >> ch;
  c = a;
  for (int i = 0; i < k; i++) {
    if (c == e) return i;
    if (ch[i] == 'L') c = (((c >> 1) & a) | (b << 1) & c);
    if (ch[i] == 'R') c = (((c << 1) & a) | (b >> 1) & c);
    if (ch[i] == 'U') c = (((c >> m) & a) | (b << m) & c);
    if (ch[i] == 'D') c = (((c << m) & a) | (b >> m) & c);
  }
  if (c == e) return k;
  return -1;
}
int main() {
  cin >> n >> m >> k;
  cout << work();
}
