#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 100;
const long long INFLL = 1e18 + 100;
const int MAXN = 3e5 + 100;
int n, m, ans;
char a[55][55];
int dx[] = {1, 2, 3, 4};
string s;
bool tr = false, lo = false;
void rec(int cur, int x, int y) {
  if (lo || tr) return;
  if (a[x][y] == 'E') {
    tr = 1;
    return;
  }
  if (cur >= s.size() || x > n || x < 1 || y > m || y < 1 || a[x][y] == '#') {
    lo = 1;
    return;
  }
  if (dx[0] == (s[cur] - 48) + 1) {
    rec(cur + 1, x + 1, y);
    if (lo || tr) return;
  } else if (dx[1] == (s[cur] - 48) + 1) {
    rec(cur + 1, x, y + 1);
    if (lo || tr) return;
  } else if (dx[2] == (s[cur] - 48) + 1) {
    rec(cur + 1, x, y - 1);
    if (lo || tr) return;
  } else {
    rec(cur + 1, x - 1, y);
    if (lo || tr) return;
  }
  if (lo || tr) return;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  srand(time(NULL));
  if (fopen("sorting"
            ".in",
            "r")) {
    freopen(
        "sorting"
        ".in",
        "r", stdin);
    freopen(
        "sorting"
        ".out",
        "w", stdout);
  }
  cin >> n >> m;
  int stx, sty;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      if (a[i][j] == 'S') {
        stx = i;
        sty = j;
      }
    }
  }
  cin >> s;
  do {
    tr = lo = false;
    rec(0, stx, sty);
    if (tr && !lo) ++ans;
  } while (next_permutation(dx, dx + 4));
  cout << ans;
  return 0;
}
