#include <bits/stdc++.h>
using namespace std;
char a[51][51];
int main() {
  int x[] = {-1, 1, 0, 0}, y[] = {0, 0, -1, 1}, mp[] = {0, 1, 2, 3}, n, m,
      start, endd, st, ed;
  string s;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'S') start = i, endd = j;
    }
  cin >> s;
  long long res = 0;
  do {
    st = start;
    ed = endd;
    for (int i = 0; i < s.size(); i++) {
      st += x[mp[s[i] - '0']];
      ed += y[mp[s[i] - '0']];
      if (st < 0 || st >= n || ed < 0 || ed >= m || a[st][ed] == '#') break;
      if (a[st][ed] == 'E') {
        res++;
        break;
      }
    }
  } while (next_permutation(mp, mp + 4));
  cout << res;
  return 0;
}
