#include <bits/stdc++.h>
using namespace std;
int di[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dj[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int N = 55;
int n, m;
char grid[N][N];
map<char, int> info;
string inst;
bool valid(int i, int j) {
  return i >= 0 && i < n && j >= 0 && j < m && grid[i][j] != '#';
}
bool canReach(int i, int j, int ind) {
  if (!valid(i, j)) return 0;
  if (grid[i][j] == 'E') return 1;
  if (ind < inst.size())
    return canReach(i + di[info[inst[ind]]], j + dj[info[inst[ind]]], ind + 1);
  return 0;
}
int main() {
  int si, sj;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", &grid[i]);
    for (int j = 0; j < m; j++)
      if (grid[i][j] == 'S') si = i, sj = j;
  }
  cin >> inst;
  int cnt = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (j == i) continue;
      for (int k = 0; k < 4; k++) {
        if (k == j || k == i) continue;
        for (int h = 0; h < 4; h++) {
          if (h == i || h == j || h == k) continue;
          info['0'] = i;
          info['1'] = j;
          info['2'] = k;
          info['3'] = h;
          cnt += canReach(si, sj, 0);
        }
      }
    }
  }
  printf("%d", cnt);
}
