#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int n, m, xs, ys, xe, ye;
char a[N][N];
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int p[4];
string s;
int k;
bool check(int x, int y) {
  return (x >= 1 && x <= n && y >= 1 && y <= m && a[x][y] != '#');
}
bool solve() {
  int x = xs, y = ys;
  if (x == xe && y == ye) return true;
  for (int i = 0; i < k; i++) {
    int d = s[i] - '0';
    x += dx[p[d]];
    y += dy[p[d]];
    if (!check(x, y)) return false;
    if (x == xe && y == ye) return true;
  }
  return false;
}
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) scanf("%c", &a[i][j]);
    scanf("\n");
  }
  cin >> s;
  k = s.length();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == 'S') {
        xs = i;
        ys = j;
      } else if (a[i][j] == 'E') {
        xe = i;
        ye = j;
      }
    }
  }
  for (int i = 0; i < 4; i++) p[i] = i;
  int ans = 0;
  while (true) {
    if (solve()) ans++;
    if (!next_permutation(p, p + 4)) break;
  }
  cout << ans;
  return 0;
}
