#include <bits/stdc++.h>
using namespace std;
const int maxn = 155;
const int maxm = 1e5 + 5;
int n, m, k;
int id[maxn][maxn];
char s[maxm];
bitset<50005> a, b, e, mp;
void init() {
  int tot = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) id[i][j] = tot++;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  init();
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; j++) {
      if (s[j] == '#')
        mp[id[i][j]] = 1;
      else
        a[id[i][j]] = 1;
      if (s[j] == 'E') e[id[i][j]] = 1;
    }
  }
  scanf("%s", s + 1);
  b = a;
  for (int i = 1; i <= k + 1; i++) {
    if (a == e) {
      printf("%d\n", i - 1);
      return 0;
    }
    if (s[i] == 'U')
      a = (((a >> m) & b) | ((mp << m) & a));
    else if (s[i] == 'D')
      a = (((a << m) & b) | ((mp >> m) & a));
    else if (s[i] == 'L')
      a = (((a >> 1) & b) | ((mp << 1) & a));
    else
      a = (((a << 1) & b) | ((mp >> 1) & a));
  }
  puts("-1");
  return 0;
}
