#include <bits/stdc++.h>
using namespace std;
char a[100][100];
string di[24] = {"dlur", "dlru", "dulr", "durl", "drlu", "drul",
                 "rdul", "rdlu", "rldu", "rlud", "rudl", "ruld",
                 "udrl", "udlr", "urdl", "urld", "uldr", "ulrd",
                 "ldru", "ldur", "lurd", "ludr", "lrdu", "lrud"};
int Sx, Sy, Ex, Ey;
char M[10000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> M;
  int c = 0;
  for (int l = 0; l < 24; l++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i][j] == 'S')
          Sx = i, Sy = j;
        else if (a[i][j] == 'E')
          Ex = i, Ey = j;
      }
    }
    int x = Sx, y = Sy;
    bool ans = false;
    for (int i = 0; M[i] != 0; i++) {
      char d = di[l][M[i] - '0'];
      if (d == 'r') y++;
      if (d == 'l') y--;
      if (d == 'u') x--;
      if (d == 'd') x++;
      if (a[x][y] == '#') break;
      if (a[x][y] == 'E') {
        ans = true;
        break;
      }
      if (x < 0 || x >= n || y < 0 || y >= m) break;
    }
    if (ans) c++;
  }
  cout << c;
  return 0;
}
