#include <bits/stdc++.h>
using namespace std;
inline void Boost() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const int NMax = 55;
string v[NMax];
int main() {
  Boost();
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  int ax, ay;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (v[i][j] == 'S') {
        ax = i;
        ay = j;
      }
    }
  }
  vector<pair<int, int> > dir;
  dir.push_back({-1, 0});
  dir.push_back({1, 0});
  dir.push_back({0, 1});
  dir.push_back({0, -1});
  vector<int> perm;
  for (int i = 0; i < 4; ++i) perm.push_back(i);
  string move;
  cin >> move;
  int mvSz = (int)move.size();
  int ans = 0;
  do {
    int x = ax;
    int y = ay;
    bool ok = false;
    for (int i = 0; i < mvSz && !ok; ++i) {
      x += dir[perm[move[i] - '0']].first;
      y += dir[perm[move[i] - '0']].second;
      if (x < 0 || x >= n || y < 0 || y >= m) {
        break;
      }
      if (v[x][y] == '#') {
        break;
      }
      if (v[x][y] == 'E') {
        ok = true;
      }
    }
    if (ok) ++ans;
  } while (next_permutation(perm.begin(), perm.end()));
  cout << ans;
  return 0;
}
