#include <bits/stdc++.h>
using namespace std;
bitset<23333> a, b, c, d;
int n, m, k;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char s;
      cin >> s;
      if (s == '#')
        b.set(i * m + j);
      else
        a.set(i * m + j);
      if (s == 'E') d.set(i * m + j);
    }
  string s;
  cin >> s;
  int i;
  c = a;
  for (int i = 0; i < k; i++) {
    if (c == d) {
      cout << i << endl;
      return 0;
    }
    if (s[i] == 'D') c = ((c << m) & a) | (c & (b >> m));
    if (s[i] == 'U') c = ((c >> m) & a) | (c & (b << m));
    if (s[i] == 'R') c = ((c << 1) & a) | (c & (b >> 1));
    if (s[i] == 'L') c = ((c >> 1) & a) | (c & (b << 1));
  }
  if (c == d)
    cout << k << endl;
  else
    cout << -1 << endl;
  return 0;
}
