#include <bits/stdc++.h>
using namespace std;
inline int nextint() {
  int x;
  scanf("%d", &x);
  return x;
}
inline long long nextll() {
  long long x;
  scanf("%lld", &x);
  return x;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
const long double PI = (long double)(3.1415926535897932384626433832795);
const long long mx_ll = numeric_limits<long long>::max();
const int mx_int = numeric_limits<int>::max();
const int mod = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const long long OO = 0x3f3f3f3f3f3f3f3fll;
const double eps = 1e-9;
const int maxn = 100123;
void solve() {}
int main() {
  string as = {
      "UDRLUDLRURDLURLDULRDULDRDURLDULRDRULDRLUDLRUDLURRDULRDLURUDLRULDRLUDRLDU"
      "LDRULDURLRDULRUDLURDLUDR"};
  int n, m;
  cin >> n >> m;
  vector<vector<char>> t(n, vector<char>(m));
  int sf, sc, ef, ec;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> t[i][j];
      if (t[i][j] == 'S')
        sf = i, sc = j;
      else if (t[i][j] == 'E') {
        ef = i, ec = j;
      }
    }
  }
  map<char, pair<int, int>> ma;
  ma['U'] = make_pair(-1, 0);
  ma['D'] = make_pair(1, 0);
  ma['R'] = make_pair(0, 1);
  ma['L'] = make_pair(0, -1);
  string dir;
  cin >> dir;
  int way = 0;
  for (int p = 0; p < 24; ++p) {
    bool puedo = true;
    int pf = sf, pc = sc;
    for (int i = 0; i < dir.length() and puedo; ++i) {
      int d = int(dir[i] - '0');
      pf += ma[as[p * 4 + d]].first;
      pc += ma[as[p * 4 + d]].second;
      puedo = pf >= 0 and pc >= 0 and pf < n and pc < m;
      if (puedo and t[pf][pc] == '#') puedo = false;
      if (puedo and t[pf][pc] == 'E') {
        way++;
        puedo = false;
      }
    }
  }
  cout << way << endl;
}
