#include <bits/stdc++.h>
using namespace std;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> cell(n);
  int sy, sx, ey, ex;
  for (int i = 0; i < n; i++) {
    cin >> cell[i];
    for (int j = 0; j < m; j++) {
      if (cell[i][j] == 'S') sy = i, sx = j;
      if (cell[i][j] == 'E') ey = i, ex = j;
    }
  }
  string s;
  cin >> s;
  int d[] = {0, 1, 2, 3};
  int res = 0;
  do {
    int y = sy, x = sx;
    bool ok = false;
    for (int i = 0; i < s.size(); i++) {
      y += dy[d[s[i] - '0']];
      x += dx[d[s[i] - '0']];
      if (y < 0 || n <= y || x < 0 || m <= x) {
        break;
      } else if (cell[y][x] == '#') {
        break;
      } else if (y == ey && x == ex) {
        ok = true;
        break;
      }
    }
    if (ok) res++;
  } while (next_permutation(d, d + 4));
  cout << res << endl;
  return 0;
}
