#include <bits/stdc++.h>
using namespace std;
char g[55][55];
char s[111];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int n, m, ans, nx, ny;
int f[4];
bool ok() {
  int x = nx, y = ny;
  for (int i = 0; s[i]; ++i) {
    x += dx[f[s[i] - '0']];
    y += dy[f[s[i] - '0']];
    if (x < 0 || x == n || y < 0 || y == m || g[x][y] == '#') return 0;
    if (g[x][y] == 'E') return 1;
  }
  return 0;
}
bool u[4];
void dfs(int c) {
  if (c == 4) {
    if (ok()) ++ans;
    return;
  }
  for (int i = 0; i < 4; ++i) {
    if (u[i] == false) {
      f[c] = i;
      u[i] = true;
      dfs(c + 1);
      u[i] = false;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> g[i];
  cin >> s;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (g[i][j] == 'S') {
        nx = i, ny = j;
        break;
      }
    }
  ans = 0;
  dfs(0);
  cout << ans << endl;
  return 0;
}
