#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, xx, yy, a[6], sz, cnt, pos[6], di[7] = {-1, 1, 0, 0},
                                               dj[7] = {0, 0, -1, 1};
string s;
char c[510][510];
void check() {
  memset(pos, 0, sizeof pos);
  pos[a[0]] = 0;
  pos[a[1]] = 1;
  pos[a[2]] = 2;
  pos[a[3]] = 3;
  int xs = x, ys = y;
  int p;
  bool ok = 0;
  for (int i = 0; i < sz; i++) {
    p = pos[s[i] - 48];
    xs += di[p];
    ys += dj[p];
    if (xs == xx && ys == yy) {
      ok = 1;
      break;
    }
    if (c[xs][ys] == '#') return;
    if (xs < 1 || xs > n || ys < 1 || ys > m) return;
  }
  if (ok) cnt++;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
      if (c[i][j] == 'S') {
        x = i;
        y = j;
      }
      if (c[i][j] == 'E') {
        xx = i;
        yy = j;
      }
    }
  cin >> s;
  sz = s.size();
  a[0] = 0;
  a[1] = 1;
  a[2] = 2;
  a[3] = 3;
  do {
    check();
  } while (next_permutation(a, a + 4));
  cout << cnt;
  return 0;
}
