#include <bits/stdc++.h>
using namespace std;
char str[51][51];
char str2[101];
int n, m;
int len2;
int check(int a, int b) {
  if (a >= 0 && a < n && b >= 0 && b < m && (str[a][b] != '#')) return 1;
  return 0;
}
int foo(string perm, int a, int b) {
  char fol[4];
  fol[perm[0] - '0'] = 'U';
  fol[perm[1] - '0'] = 'D';
  fol[perm[2] - '0'] = 'L';
  fol[perm[3] - '0'] = 'R';
  for (int i = 0; i < len2; i++) {
    if (check(a, b) == 0) return 0;
    if (str[a][b] == 'E') return 1;
    if (fol[str2[i] - '0'] == 'U') {
      a--;
    }
    if (fol[str2[i] - '0'] == 'D') {
      a++;
    }
    if (fol[str2[i] - '0'] == 'L') {
      b--;
    }
    if (fol[str2[i] - '0'] == 'R') {
      b++;
    }
  }
  if (check(a, b) == 0) return 0;
  if (str[a][b] == 'E') return 1;
  return 0;
}
int main(void) {
  scanf("%d %d", &n, &m);
  int a, b;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf(" %c", &str[i][j]);
      if (str[i][j] == 'S') {
        a = i;
        b = j;
      }
    }
  }
  int ans = 0;
  scanf(" %s", str2);
  len2 = strlen(str2);
  string perm = "0123";
  ans += foo(perm, a, b);
  while (next_permutation(perm.begin(), perm.end())) {
    ans += foo(perm, a, b);
  }
  printf("%d\n", ans);
  return 0;
}
