#include <bits/stdc++.h>
const int max_n = 150;
const unsigned int lowest = 31;
const int size = (max_n >> 5) + 1;
struct row {
  unsigned int bits[size];
  void set_bit(unsigned int j) { bits[j >> 5] |= (1 << (j & lowest)); }
  bool get_bit(unsigned int j) {
    return ((bits[j >> 5] >> (j & lowest)) & 1) == 1;
  }
  bool is_zero() {
    for (int i = 0; i < size; ++i)
      if (bits[i]) return false;
    return true;
  }
};
row operator&(row a, row b) {
  row c;
  for (int i = 0; i < size; ++i) c.bits[i] = a.bits[i] & b.bits[i];
  return c;
}
row operator|(row a, row b) {
  row c;
  for (int i = 0; i < size; ++i) c.bits[i] = a.bits[i] | b.bits[i];
  return c;
}
row operator~(row a) {
  row c;
  for (int i = 0; i < size; ++i) c.bits[i] = ~a.bits[i];
  return c;
}
row left(row a) {
  for (int i = 0; i < size - 1; ++i) {
    a.bits[i] >>= 1;
    if (a.bits[i + 1] & 1) a.bits[i] |= (1 << lowest);
  }
  a.bits[size - 1] >>= 1;
  return a;
}
row right(row a) {
  for (int i = size - 1; i > 0; --i) {
    a.bits[i] <<= 1;
    if (a.bits[i - 1] & (1 << lowest)) a.bits[i] |= 1;
  }
  a.bits[0] <<= 1;
  return a;
}
int ei, ej, n, m, k;
row table[max_n], where[max_n];
bool check() {
  for (int i = 0; i < n; ++i)
    if ((i != ei) && !where[i].is_zero()) return false;
  for (int j = 0; j < m; ++j)
    if ((j != ej) && where[ei].get_bit(j)) return false;
  return true;
}
int main() {
  memset(table, 0, sizeof(table));
  memset(where, 0, sizeof(where));
  scanf("%d%d%d\n", &n, &m, &k);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      char c;
      scanf("%c", &c);
      if (c == 'E') ei = i, ej = j, c = '.';
      if (c == '.') table[i].set_bit(j), where[i].set_bit(j);
    }
    scanf("\n");
  }
  if (check()) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= k; ++i) {
    char c;
    scanf("%c", &c);
    switch (c) {
      case 'L':
        for (int r = 1; r <= n - 2; ++r)
          where[r] =
              (left(where[r]) & table[r]) | (where[r] & ~right(table[r]));
        break;
      case 'R':
        for (int r = 1; r <= n - 2; ++r)
          where[r] =
              (right(where[r]) & table[r]) | (where[r] & ~left(table[r]));
        break;
      case 'D':
        for (int r = n - 2; r >= 1; --r)
          where[r] = (where[r - 1] & table[r]) | (where[r] & ~table[r + 1]);
        break;
      case 'U':
        for (int r = 1; r <= n - 2; ++r)
          where[r] = (where[r + 1] & table[r]) | (where[r] & ~table[r - 1]);
        break;
    }
    if (check()) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
