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