#include <bits/stdc++.h>
int ans = 0, A, B, C, D;
char s[100][100], ch[200];
void _c(int a, int b, int c, int d) {
  int cnt = 1, i, x, y;
  while (cnt <= 4) {
    x = A, y = B;
    for (i = 0; i < strlen(ch); i++) {
      if (ch[i] == a + 48) x--;
      if (ch[i] == b + 48) x++;
      if (ch[i] == c + 48) y--;
      if (ch[i] == d + 48) y++;
      if (s[x][y] != '.' && s[x][y] != 'S') break;
    }
    if (s[x][y] == 'E') ans++;
    x = a;
    a = b;
    b = c;
    c = d;
    d = x;
    cnt++;
  }
}
int main() {
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      if (s[i][j] == 'S') {
        A = i;
        B = j;
      }
      if (s[i][j] == 'E') {
        C = i;
        D = j;
      }
    }
  scanf("%s", ch);
  _c(0, 1, 2, 3);
  _c(0, 1, 3, 2);
  _c(0, 2, 1, 3);
  _c(0, 2, 3, 1);
  _c(0, 3, 1, 2);
  _c(0, 3, 2, 1);
  printf("%d", ans);
  return 0;
}
