#include <bits/stdc++.h>
using namespace std;
char v[55][55];
int n, m;
char s[111];
int tam;
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int ans;
int mov[] = {0, 1, 2, 3};
int sx, sy;
int ex, ey;
void bfs() {
  int x = sx, y = sy;
  for (int i = 0; i < tam; ++i) {
    x += dx[mov[s[i] - '0']];
    y += dy[mov[s[i] - '0']];
    if (x < 0 || y < 0 || x >= n || y >= m || v[x][y] == '#') return;
    if (v[x][y] == 'E') {
      ans++;
      return;
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", v[i]);
    for (int j = 0; j < m; ++j) {
      if (v[i][j] == 'S') {
        sx = i;
        sy = j;
      }
      if (v[i][j] == 'E') {
        ex = i;
        ey = j;
      }
    }
  }
  scanf("%s", s);
  tam = strlen(s);
  do {
    bfs();
  } while (next_permutation(mov, mov + 4));
  printf("%d\n", ans);
  return 0;
}
