#include <bits/stdc++.h>
using namespace std;
const int N = 155;
int n, m, k;
int ex, ey;
string s;
char a[N][N];
bitset<N> cur[N], spasite[N], blocked[N], new_cur[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  int ss = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') {
        blocked[i][j] = true;
      } else {
        cur[i][j] = true;
        spasite[i][j] = true;
        ss++;
        if (a[i][j] == 'E') {
          ex = i;
          ey = j;
        }
      }
    }
  }
  if (ss == 1) {
    return cout << 0, 0;
  }
  cin >> s;
  for (int z = 1; z <= k; z++) {
    auto it = s[z - 1];
    ss = 0;
    if (it == 'L') {
      for (int i = 1; i <= n; i++) {
        new_cur[i] =
            ((spasite[i] & (cur[i] >> 1)) | (cur[i] & (blocked[i] << 1)));
        ss += new_cur[i].count();
      }
    } else if (it == 'R') {
      for (int i = 1; i <= n; i++) {
        new_cur[i] =
            ((spasite[i] & (cur[i] << 1)) | (cur[i] & (blocked[i] >> 1)));
        ss += new_cur[i].count();
      }
    } else if (it == 'D') {
      for (int i = 1; i <= n; i++) {
        if (i == 1) {
          new_cur[i] = (cur[i] & blocked[i + 1]);
        } else if (i == n) {
          new_cur[i] = (cur[i - 1] & spasite[i]);
        } else {
          new_cur[i] = ((cur[i] & blocked[i + 1]) | (cur[i - 1] & spasite[i]));
        }
        ss += new_cur[i].count();
      }
    } else {
      for (int i = 1; i <= n; i++) {
        if (i == 1) {
          new_cur[i] = (cur[i + 1] & spasite[i]);
        } else if (i == n) {
          new_cur[i] = (cur[i] & blocked[i - 1]);
        } else {
          new_cur[i] = ((cur[i] & blocked[i - 1]) | (cur[i + 1] & spasite[i]));
        }
        ss += new_cur[i].count();
      }
    }
    if (ss == 1 && new_cur[ex][ey] == 1) {
      return cout << z, 0;
    }
    for (int i = 1; i <= n; i++) {
      cur[i] = new_cur[i];
    }
  }
  cout << "-1";
}
