#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
const int N = 200005;
int n, m, d[30][6], cnt, len;
char s[110][110], si[110];
bool is(int r, int c) {
  return r > 0 && r <= n && c > 0 && c <= m && s[r][c] != '#';
}
bool dfs(int k, int r, int c, int f) {
  if (s[r][c] == 'E') return true;
  if (k == len + 1) return false;
  int df, tr = r, tc = c;
  for (int i = 0; i <= 3; ++i)
    if (d[f][i] == si[k] - '0') df = i;
  if (df == 0)
    tc--;
  else if (df == 1)
    tc++;
  else if (df == 2)
    tr--;
  else
    tr++;
  if (!is(tr, tc))
    return false;
  else
    return dfs(k + 1, tr, tc, f);
}
void get() {
  cnt = 0;
  for (int i = 0; i <= 3; ++i)
    for (int j = 0; j <= 3; ++j)
      if (j != i)
        for (int l = 0; l <= 3; ++l)
          if (l != i && l != j)
            for (int k = 0; k <= 3; ++k)
              if (k != i && k != l && k != j)
                d[++cnt][0] = i, d[cnt][1] = j, d[cnt][2] = l, d[cnt][3] = k;
}
int main() {
  cin >> n >> m;
  int tr, tc;
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s[i] + 1);
    for (int j = 1; j <= m; ++j)
      if (s[i][j] == 'S') tr = i, tc = j;
  }
  scanf("%s", si + 1);
  len = strlen(si + 1);
  get();
  int ans = 0;
  for (int i = 1; i <= cnt; ++i) {
    if (dfs(1, tr, tc, i)) ++ans;
  }
  cout << ans << endl;
  return 0;
}
