#include <bits/stdc++.h>
char a[60][60];
char s[110];
int n, m;
int main(void) {
  scanf("%d%d", &n, &m);
  char c = getchar();
  int i, j;
  int x, y;
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      a[i][j] = getchar();
      if (a[i][j] == 'S') {
        x = i;
        y = j;
      }
    }
    c = getchar();
  }
  gets(s);
  int l = strlen(s);
  int p, q, r, t, b, x1, y1;
  int step = 0;
  for (p = 0; p < 4; ++p) {
    for (q = 0; q < 4; ++q) {
      for (r = 0; r < 4; ++r) {
        for (t = 0; t < 4; ++t) {
          if (p != q && p != r && p != t && q != r && q != t && r != t) {
            x1 = x;
            y1 = y;
            for (b = 0; b < l; ++b) {
              if (s[b] == p + 48) {
                x1++;
              }
              if (s[b] == q + 48) {
                x1--;
              }
              if (s[b] == r + 48) {
                y1++;
              }
              if (s[b] == t + 48) {
                y1--;
              }
              if (x1 < 0 || x1 >= n || y1 < 0 || y1 >= m || a[x1][y1] == '#') {
                break;
              }
              if (a[x1][y1] == 'E') {
                ++step;
                break;
              }
            }
          }
        }
      }
    }
  }
  printf("%d", step);
}
