#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  char a[24][4];
  string ss[24] = {"DLRU", "DLUR", "DRLU", "DRUL", "DULR", "DURL",
                   "LDRU", "LDUR", "LRDU", "LRUD", "LUDR", "LURD",
                   "RDLU", "RDUL", "RLDU", "RLUD", "RUDL", "RULD",
                   "UDLR", "UDRL", "ULDR", "ULRD", "URDL", "URLD"};
  int p, q;
  for (p = 0; p < 24; p++) {
    for (q = 0; q < 4; q++) {
      a[p][q] = ss[p][q];
    }
  }
  int n, m;
  cin >> n >> m;
  char b[n][m];
  int i, j, posx, posy, dx, dy;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> b[i][j];
      if (b[i][j] == 'S') {
        posx = i;
        posy = j;
        b[i][j] = '.';
      }
      if (b[i][j] == 'E') {
        dx = i;
        dy = j;
        b[i][j] = '.';
      }
    }
  }
  string s;
  int pinx = posx, piny = posy;
  cin >> s;
  int l = s.length(), f = 0;
  for (i = 0; i < 24; i++) {
    posx = pinx;
    posy = piny;
    for (j = 0; j < l; j++) {
      if (posx == dx && posy == dy) {
        f++;
        break;
      }
      char x = a[i][s[j] - '0'];
      if (x == 'L') {
        if (posy == 0 || b[posx][posy - 1] == '#')
          break;
        else
          posy--;
      }
      if (x == 'R') {
        if (posy == m - 1 || b[posx][posy + 1] == '#')
          break;
        else
          posy++;
      }
      if (x == 'U') {
        if (posx == 0 || b[posx - 1][posy] == '#')
          break;
        else
          posx--;
      }
      if (x == 'D') {
        if (posx == n - 1 || b[posx + 1][posy] == '#')
          break;
        else
          posx++;
      }
    }
    if (j == l && posx == dx && posy == dy) f++;
  }
  cout << f;
  return 0;
}
