#include <bits/stdc++.h>
using namespace std;
int n, m, d[1001], t, posis, posjs, posie, posje, j, asd, i, ans;
string ss, res, s;
bool was[10001];
char a[101][101];
vector<string> v;
void go(int l) {
  int i;
  if (l > t) {
    for (i = 1; i <= t; i++) res += ss[d[i] - 1];
    v.push_back(res);
    res = "";
    return;
  }
  for (i = 1; i <= t; i++)
    if (was[i] == false) {
      was[i] = true;
      d[l] = i;
      go(l + 1);
      was[i] = false;
    }
}
int otpr(int q, int w, int e, int r) {
  if (v[e][r] == 'D') {
    if (a[q + 1][w] != '#' && q + 1 <= n)
      return 1;
    else
      return 0;
  }
  if (v[e][r] == 'L') {
    if (a[q][w - 1] != '#' && w - 1 > 0)
      return 2;
    else
      return 0;
  }
  if (v[e][r] == 'U') {
    if (a[q - 1][w] != '#' && q - 1 > 0)
      return 3;
    else
      return 0;
  }
  if (v[e][r] == 'R') {
    if (a[q][w + 1] != '#' && w + 1 <= m)
      return 4;
    else
      return 0;
  }
}
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'S') {
        posis = i;
        posjs = j;
      }
      if (a[i][j] == 'E') {
        posie = i;
        posje = j;
      }
    }
  cin >> s;
  ss = "DLUR";
  t = ss.size();
  go(1);
  int zx = posis;
  int zc = posjs;
  int pl;
  for (i = 0; i < v.size(); i++) {
    for (j = 0; j < s.size(); j++) {
      asd = otpr(posis, posjs, i, s[j] - '0');
      if (asd == 1) posis++;
      if (asd == 2) posjs--;
      if (asd == 3) posis--;
      if (asd == 4) posjs++;
      if (asd == 0) break;
      if (posis == posie && posjs == posje) {
        ans++;
        break;
      }
    }
    posis = zx;
    posjs = zc;
  }
  cout << ans;
  return 0;
}
