#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 10;
const int INF = 1e9 + 7;
string st[55];
string p;
pair<int, int> S, E;
vector<int> a;
int n, m;
int dirx[] = {-1, +1, 0, 0};
int diry[] = {0, 0, +1, -1};
inline bool check() {
  pair<int, int> cur = S;
  for (int i = 0; i < p.size(); i++) {
    cur.first += dirx[a[p[i] - '0']];
    cur.second += diry[a[p[i] - '0']];
    if (cur == E) {
      return true;
    }
    if (cur.first < 0 || cur.first >= n || cur.second < 0 || cur.second >= m) {
      return false;
    }
    if (st[cur.first][cur.second] == '#') {
      return false;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> st[i];
    for (int j = 0; j < m; j++) {
      if (st[i][j] == 'S') {
        S.first = i;
        S.second = j;
      } else if (st[i][j] == 'E') {
        E.first = i;
        E.second = j;
      }
    }
  }
  cin >> p;
  for (int i = 0; i <= 3; i++) {
    a.push_back(i);
  }
  int ans = 0;
  do {
    if (check()) {
      ans++;
    }
  } while (next_permutation(a.begin(), a.end()));
  cout << ans;
  return 0;
}
