#include <bits/stdc++.h>
using namespace std;
string st;
int n, m, l, ans;
void solve() {
  static bitset<25000> b1, b2, a, e;
  for (int i = 0; i < n; i++) {
    cin >> st;
    for (int j = 0; j < m; j++) {
      if (st[j] == '#')
        b2.set(i * m + j);
      else
        b1.set(i * m + j);
      if (st[j] == 'E') e.set(i * m + j);
    }
  }
  a = b1;
  cin >> st;
  for (int i = 0; i < l; i++) {
    if (a == e) {
      ans = i;
      return;
    }
    if (st[i] == 'U') a = ((a >> m) & b1) | (a & (b2 << m));
    if (st[i] == 'D') a = ((a << m) & b1) | (a & (b2 >> m));
    if (st[i] == 'L') a = ((a >> 1) & b1) | (a & (b2 << 1));
    if (st[i] == 'R') a = ((a << 1) & b1) | (a & (b2 >> 1));
  }
  if (a == e)
    ans = l;
  else
    ans = -1;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m >> l;
  solve();
  cout << ans << endl;
  return 0;
}
