#include <bits/stdc++.h>
using namespace std;
int main() {
  bitset<22510> now, obs, ori, des;
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i <= n - 1; i++) {
    string s;
    cin >> s;
    for (int j = 0; j <= m - 1; j++) {
      if (s[j] == '.' || s[j] == 'E') ori.set(i * m + j);
      if (s[j] == 'E') des.set(i * m + j);
    }
  }
  obs = ori;
  obs.flip();
  now = ori;
  string s;
  cin >> s;
  int i;
  for (i = 0; i < k; i++) {
    if (des == now) break;
    if (s[i] == 'U') now = (((now >> m) & ori) | (now & (obs << m)));
    if (s[i] == 'D') now = (((now << m) & ori) | (now & (obs >> m)));
    if (s[i] == 'L') now = (((now >> 1) & ori) | (now & (obs << 1)));
    if (s[i] == 'R') now = (((now << 1) & ori) | (now & (obs >> 1)));
  }
  cout << (des == now ? i : -1) << endl;
  return 0;
}
