#include <bits/stdc++.h>
using namespace std;
int n, m;
int change[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
char square[55][55] = {0};
int step[105] = {0}, t = 0;
int ex, ey, sx, sy, ans = 0;
void check(int x, int y, int z, int w) {
  int r = sx, c = sy, a[4] = {x, y, z, w};
  for (int i = 0; i < t; i++) {
    r += change[a[step[i]]][0];
    c += change[a[step[i]]][1];
    if (r < 0 || c < 0 || r >= n || c >= m || square[r][c] == '#') return;
    if (r == ex && c == ey) {
      ans++;
      return;
    }
  }
  return;
}
void run() {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (i == j) continue;
      for (int k = 0; k < 4; k++) {
        if (k == j || k == i) continue;
        for (int l = 0; l < 4; l++) {
          if (i == l || k == l || j == l) continue;
          check(i, j, k, l);
        }
      }
    }
  }
}
int main() {
  cin >> n >> m;
  char c = getchar();
  for (int i = 0; i < n; i++) {
    while (c != '.' && c != '#' && c != 'S' && c != 'E') c = getchar();
    for (int j = 0; j < m; j++) {
      square[i][j] = c;
      if (c == 'S') {
        sx = i;
        sy = j;
      } else if (c == 'E') {
        ex = i;
        ey = j;
      }
      c = getchar();
    }
  }
  while (c > '3' || c < '0') c = getchar();
  while (c >= '0' && c <= '3') {
    step[t] = c - '0';
    c = getchar();
    t++;
  }
  run();
  cout << ans;
  return 0;
}
