#include <bits/stdc++.h>
using namespace std;
template <int __>
struct ia {
  int a[__], n;
  ia(int n = 0) : n(n) {}
  void rev() { reverse(a + 1, a + n + 1); }
  void hp() { make_heap(a + 1, a + n + 1); }
  int& operator[](int x) { return a[x]; }
  void sf() {
    for (int i = (1); i <= (n); i++) scanf("%d", a + i);
  }
  void mem(int x) { memset(a, x, sizeof(a)); }
  void sup() { sort(a + 1, a + n + 1, less<int>()); }
  void sdn() { sort(a + 1, a + n + 1, greater<int>()); }
  void uq() { this->sup(), n = unique(a + 1, a + n + 1) - a - 1; }
  bool nexp() { return next_permutation(a + 1, a + n + 1); }
  int lb(int x) { return lower_bound(a + 1, a + n + 1, x) - a; }
  int ub(int x) { return upper_bound(a + 1, a + n + 1, x) - a; }
  void pf() {
    for (int i = (1); i <= (n); i++) printf("%d%c", a[i], i == n ? '\n' : ' ');
  }
  ia operator+(const ia& b) {
    ia<__> c(max(n, b.n));
    c.mem(0);
    for (int i = 1; i <= (c.n); i++) c[i] = a[i] + b.a[i];
    return c;
  }
  ia operator-(const ia& b) {
    ia<__> c(max(n, b.n));
    c.mem(0);
    for (int i = 1; i <= (c.n); i++) c[i] = a[i] - b.a[i];
    return c;
  }
  ia operator*(const ia& b) {
    ia<__> c;
    c.mem(0);
    for (int i = 1; i <= ((*this).n); i++)
      for (int j = 1; j <= (b.n); j++)
        c.n = max(c.n, i + j - 1), c[i + j - 1] += a[i] * b.a[j];
    return c;
  }
};
struct node {
  int x, y;
  node(int x, int y) : x(x), y(y) {}
};
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
char a[55][55];
char op[105];
ia<5> b(4);
int main() {
  for (int i = 1; i <= (b.n); i++) b[i] = i - 1;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (n); i++) scanf("%s", a[i] + 1);
  scanf("%s", op + 1);
  int len = strlen(op + 1);
  node st(0, 0), ed(0, 0);
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (m); j++)
      if (a[i][j] == 'S')
        st = node(i, j);
      else if (a[i][j] == 'E')
        ed = node(i, j);
  int ans = 0;
  while (1) {
    node now = st;
    bool flag = false;
    for (int i = (1); i <= (len); i++) {
      int x = op[i] - '0';
      for (int j = (1); j <= (4); j++)
        if (x == b[j]) {
          now.x = now.x + dx[j];
          now.y = now.y + dy[j];
          break;
        }
      if (now.x < 1 || now.x > n) {
        flag = false;
        break;
      }
      if (now.y < 1 || now.y > m) {
        flag = false;
        break;
      }
      if (a[now.x][now.y] == '#') {
        flag = false;
        break;
      }
      if (a[now.x][now.y] == 'E') {
        flag = true;
        break;
      }
    }
    if (flag) ans++;
    if (!b.nexp()) break;
  }
  printf("%d\n", ans);
  return 0;
}
