#include <bits/stdc++.h>
using namespace std;
int main(void) {
  char grid[53][53];
  memset(grid, 0, sizeof grid);
  int n, m;
  cin >> n >> m;
  int sx, sy, ex, ey;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
      if (grid[i][j] == 'S') {
        sx = i;
        sy = j;
      }
      if (grid[i][j] == 'E') {
        ex = i;
        ey = j;
      }
    }
  }
  string s;
  cin >> s;
  string dir = "0123";
  int cnt = 0, dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
  do {
    int cx = sx, cy = sy;
    bool ok = false;
    for (int i = 0; i < s.length(); i++) {
      int cm = s[i] - '0', mv = dir[cm] - '0';
      cx += dx[mv];
      cy += dy[mv];
      if (cx < 0 || cy < 0 || cx >= n || cy >= m || grid[cx][cy] == '#') break;
      if (cx == ex && cy == ey) {
        ok = true;
        break;
      }
    }
    if (ok) cnt++;
  } while (next_permutation(dir.begin(), dir.end()));
  cout << cnt << endl;
  return 0;
}
