#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int N = 60;
const int inf32 = 1e32;
const long long inf64 = 1e18;
char ar[N][N];
pair<int, int> steps[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
pair<int, int> s, f;
string coms;
bool check(vector<int> &perm) {
  pair<int, int> cur = s;
  for (auto &x : coms) {
    cur = {cur.first + steps[perm[x]].first,
           cur.second + steps[perm[x]].second};
    if (ar[cur.first][cur.second] == '#') return 0;
    if (cur == f) return 1;
  }
  return 0;
}
void solve() {
  int n, m, cnt = 0;
  cin >> n >> m;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) ar[i][j] = '#';
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> ar[i][j];
      if (ar[i][j] == 'S') s = {i, j};
      if (ar[i][j] == 'E') f = {i, j};
    }
  }
  cin >> coms;
  for (auto &x : coms) x -= '0';
  vector<int> perm;
  for (int i = 0; i < 4; ++i) perm.push_back(i);
  do {
    cnt += check(perm);
  } while (next_permutation(perm.begin(), perm.end()));
  cout << cnt;
}
int main() {
  solve();
  return 0;
}
