#include <bits/stdc++.h>
using namespace std;
bitset<160> a[160];
bitset<160> b[160];
bitset<160> d;
bitset<160> ro[160];
bitset<160> cl[160];
bitset<160> cr[160];
bitset<160> cu[160];
bitset<160> cd[160];
char c[160], ll[100005];
int i, j, k, l, m, n, s, ans, pp;
int main() {
  cin >> n >> m >> l;
  pp = 0;
  for (i = 1; i <= n; ++i) {
    scanf("%s", c);
    for (j = 1; j <= m; ++j) {
      if (c[j - 1] == '.') ro[i][j] = 1, pp = 1;
      if (c[j - 1] == '#') cu[i + 1][j] = 1, cd[i - 1][j] = 1, b[i][j] = 1;
      if (c[j - 1] == 'E') ro[i][j] = 1, a[i][j] = 1;
    }
    cl[i] = (b[i] << 1);
    cr[i] = (b[i] >> 1);
  }
  if (pp == 0) {
    cout << 0;
    exit(0);
  }
  scanf("%s", ll);
  for (i = 1; i <= l; ++i) {
    if (ll[i - 1] == 'L') {
      for (j = 1; j <= n; ++j)
        ro[j] = ((((ro[j] & cl[j]) ^ ro[j]) >> 1) | (ro[j] & cl[j]));
    }
    if (ll[i - 1] == 'R') {
      for (j = 1; j <= n; ++j)
        ro[j] = ((((ro[j] & cr[j]) ^ ro[j]) << 1) | (ro[j] & cr[j]));
    }
    if (ll[i - 1] == 'U') {
      for (j = 1; j <= n; ++j) {
        ro[j] = (((ro[j + 1] & cu[j + 1]) ^ ro[j + 1]) | (ro[j] & cu[j]));
      }
    }
    if (ll[i - 1] == 'D') {
      for (j = n; j >= 1; --j) {
        ro[j] = (((ro[j - 1] & cd[j - 1]) ^ ro[j - 1]) | (ro[j] & cd[j]));
      }
    }
    for (j = 1; j <= n; ++j) {
      d.reset();
      d = (ro[j] ^ a[j]);
      s = d.count();
      if (s) break;
      if (j == n) {
        cout << i;
        exit(0);
      }
    }
  }
  cout << "-1";
  return 0;
}
