#include <bits/stdc++.h>
const int N = 155;
using namespace std;
typedef bitset<N * N> bs;
bs cur, res, cnl, cnr, cnu, cnd, wrld;
int n, m, k;
char ar[N][N];
int pos(int i, int j) { return j + m * (i - 1); }
void PRINT(bs cnl) {
  for (int x = 1; x <= n; x++) {
    for (int y = 1; y <= m; y++) {
      cout << cnl[pos(x, y)];
    }
    cout << endl;
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> ar[i][j];
      if (ar[i][j] == 'E') {
        res[pos(i, j)] = 1;
        ar[i][j] = '.';
      }
      if (ar[i][j] == '.') {
        cur[pos(i, j)] = 1;
        wrld[pos(i, j)] = 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (ar[i][j] == '.') {
        if (ar[i][j + 1] == '#') cnr[pos(i, j)] = 1;
        if (ar[i][j - 1] == '#') cnl[pos(i, j)] = 1;
        if (ar[i - 1][j] == '#') cnu[pos(i, j)] = 1;
        if (ar[i + 1][j] == '#') cnd[pos(i, j)] = 1;
      } else {
        cnr[pos(i, j)] = cnl[pos(i, j)] = cnd[pos(i, j)] = cnu[pos(i, j)] = 1;
      }
    }
  }
  string s;
  cin >> s;
  if (cur == res) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < k; i++) {
    if (s[i] == 'L') {
      cur = ((cur & (~cnl)) >> 1) | (cur & cnl);
    } else if (s[i] == 'R') {
      cur = ((cur & (~cnr)) << 1) | (cur & cnr);
    } else if (s[i] == 'D') {
      cur = ((cur & (~cnd)) << m) | (cur & cnd);
    } else {
      cur = ((cur & (~cnu)) >> m) | (cur & cnu);
    }
    if (cur == res) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
