#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[55][55];
pair<int, int> st, ed;
char in[105];
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'S') {
        st = pair<int, int>(i, j);
      }
    }
  }
  scanf("%s", in);
}
bool safe(pair<int, int> ps) {
  if (ps.first < 0 || ps.first >= n) return false;
  if (ps.second < 0 || ps.second >= m) return false;
  if (s[ps.first][ps.second] == '#') return false;
  return true;
}
bool isgoal(pair<int, int> ps) {
  if (s[ps.first][ps.second] == 'E') return true;
  return false;
}
void process() {
  vector<pair<int, int> > d;
  d.push_back(pair<int, int>(-1, 0));
  d.push_back(pair<int, int>(0, -1));
  d.push_back(pair<int, int>(0, 1));
  d.push_back(pair<int, int>(1, 0));
  int ans = 0;
  int l = strlen(in);
  do {
    pair<int, int> ps = st;
    bool good = false;
    for (int i = 0; i < l; i++) {
      ps.first += d[in[i] - '0'].first;
      ps.second += d[in[i] - '0'].second;
      if (!safe(ps)) break;
      if (isgoal(ps)) {
        good = true;
        break;
      }
    }
    if (good) ans++;
  } while (next_permutation(d.begin(), d.end()));
  printf("%d\n", ans);
}
int main() {
  init();
  process();
  return 0;
}
