#include <bits/stdc++.h>
using namespace std;
struct Line {
  unsigned int a[5];
  void setAll() {
    for (int i = 0; i < 5; i++) a[i] = 0xffffffff;
  }
  void resetAll() {
    for (int i = 0; i < 5; i++) a[i] = 0;
  }
  void And(const Line &l) {
    for (int i = 0; i < 5; i++) a[i] &= l.a[i];
  }
  void Or(const Line &l) {
    for (int i = 0; i < 5; i++) a[i] |= l.a[i];
  }
  void shiftRight() {
    for (int i = 4; i >= 0; i--) {
      a[i] <<= 1;
      if (i != 0 && a[i - 1] >= (unsigned)0x80000000) a[i]++;
    }
  }
  void shiftLeft() {
    for (int i = 0; i < 5; i++) {
      a[i] >>= 1;
      if (i != 4 && (a[i + 1] & 1) != 0) a[i] += (unsigned)0x80000000;
    }
  }
  void set(int pos, int value) {
    if (value) {
      a[pos / 32] |= ((unsigned)1 << (pos & 31));
    } else {
      a[pos / 32] &= ~((unsigned)1 << (pos & 31));
    }
  }
  int countUpToTwo() {
    int res = 0;
    unsigned x;
    for (int i = 0; i < 5 && res < 2; i++) {
      x = a[i];
      while (x && res < 2) {
        x &= x - 1;
        res++;
      }
    }
    return res;
  }
  bool test(int pos) {
    return (a[pos / 32] & ((unsigned)1 << (pos & 31))) != 0;
  }
};
int n, m, k;
char s[150][151];
Line a[150], empty[150], wall[150];
char cmd[100001];
int ei, ej;
bool enough() {
  int cnt = 0;
  for (int i = 0; i < n && cnt < 2; i++) cnt += a[i].countUpToTwo();
  assert(cnt != 0);
  if (cnt > 1) return false;
  return a[ei].test(ej);
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  scanf("%s", cmd);
  for (int i = 0; i < n; i++) {
    a[i].resetAll();
    wall[i].setAll();
    for (int j = 0; j < m; j++) {
      if (s[i][j] != '#') a[i].set(j, 1), wall[i].set(j, 0);
      if (s[i][j] == 'E') ei = i, ej = j;
    }
    empty[i] = a[i];
  }
  int pos = 0;
  Line tmp;
  while (pos < k && !enough()) {
    int ch = cmd[pos++];
    if (ch == 'L') {
      for (int i = 0; i < n; i++) {
        tmp = wall[i];
        tmp.shiftRight();
        tmp.And(a[i]);
        a[i].shiftLeft();
        a[i].Or(tmp);
        a[i].And(empty[i]);
      }
    } else if (ch == 'R') {
      for (int i = 0; i < n; i++) {
        tmp = wall[i];
        tmp.shiftLeft();
        tmp.And(a[i]);
        a[i].shiftRight();
        a[i].Or(tmp);
        a[i].And(empty[i]);
      }
    } else if (ch == 'U') {
      for (int i = 1; i < n - 1; i++) {
        tmp = wall[i - 1];
        tmp.And(a[i]);
        a[i] = a[i + 1];
        a[i].Or(tmp);
        a[i].And(empty[i]);
      }
      a[0].resetAll();
      a[n - 1].resetAll();
    } else {
      for (int i = n - 2; i > 0; i--) {
        tmp = wall[i + 1];
        tmp.And(a[i]);
        a[i] = a[i - 1];
        a[i].Or(tmp);
        a[i].And(empty[i]);
      }
      a[0].resetAll();
      a[n - 1].resetAll();
    }
  }
  if (pos == k && !enough()) pos = -1;
  printf("%d\n", pos);
  return 0;
}
