#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 55;
string s[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> s[i];
  int sx, sy, ex, ey;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == 'S') sx = i, sy = j;
      if (s[i][j] == 'E') ex = i, ey = j;
    }
  string w;
  cin >> w;
  string p = "ULDR";
  sort((p).begin(), (p).end());
  map<char, int> dx = {{'D', -1}, {'U', +1}};
  map<char, int> dy = {{'L', -1}, {'R', +1}};
  int ans = 0;
  do {
    bool ok = true;
    int x = sx, y = sy;
    for (int i = 0; i < w.size(); ++i) {
      if (x == ex && y == ey) break;
      if (x < 0 || x >= n || y < 0 || y >= m || s[x][y] == '#') {
        ok = false;
        break;
      }
      x += dx[p[w[i] - '0']];
      y += dy[p[w[i] - '0']];
    }
    if (ok && x == ex && y == ey) ++ans;
  } while (next_permutation((p).begin(), (p).end()));
  cout << ans << endl;
  return 0;
}
