#include <bits/stdc++.h>
using namespace std;
int n, m, p, mappings, mapping[] = {0, 1, 2, 3};
pair<int, int> S, E, location;
set<pair<int, int> > obstacle;
char s[101];
bool stop;
bool reached_exit(const int direction) {
  if ((direction == 0 && location.first == 1) ||
      (direction == 1 && location.first == n) ||
      (direction == 2 && location.second == 1) ||
      (direction == 3 && location.second == m)) {
    stop = true;
    return false;
  }
  pair<int, int> new_location = location;
  switch (direction) {
    case 0:
      new_location.first--;
      break;
    case 1:
      new_location.first++;
      break;
    case 2:
      new_location.second--;
      break;
    default:
      new_location.second++;
  }
  if (new_location == E) return true;
  if (obstacle.find(new_location) != obstacle.end()) {
    stop = true;
    return false;
  }
  location = new_location;
  return false;
}
bool valid_mapping() {
  location = S, stop = false;
  for (int i = 0; i < p && !stop; i++)
    if (reached_exit(mapping[s[i] - '0'])) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  scanf("%i %i", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    for (int j = 0, k = 1; s[j] != 0; j = k++) switch (s[j]) {
        case 'S':
          S.first = i, S.second = k;
          break;
        case 'E':
          E.first = i, E.second = k;
          break;
        case '#':
          obstacle.emplace(i, k);
          break;
      }
  }
  scanf("%s", s), p = strlen(s);
  do
    if (valid_mapping()) mappings++;
  while (next_permutation(mapping, mapping + 4));
  printf("%i", mappings);
}
