#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  int sx, sy, ex, ey;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'S') {
        sx = i;
        sy = j;
      } else if (s[i][j] == 'E') {
        ex = i;
        ey = j;
      }
    }
  }
  string comm;
  cin >> comm;
  string p = "0123";
  int cnt = 0;
  do {
    int tx = sx, ty = sy;
    for (int i = 0; i < (int)comm.size(); i++) {
      int c = comm[i] - '0';
      c = p[c] - '0';
      tx += dx[c];
      ty += dy[c];
      if (tx < 0 || tx >= n) break;
      if (ty < 0 || ty >= m) break;
      if (s[tx][ty] == '#') break;
      if (tx == ex && ty == ey) {
        cnt++;
        break;
      }
    }
  } while (next_permutation(p.begin(), p.end()));
  printf("%d", cnt);
  return 0;
}
