#include <bits/stdc++.h>
using namespace std;
char maze[50][50];
char instructions[129];
int instructionmap[4];
int taken[4];
pair<int, int> start;
int solve(int m, int n, int it) {
  if (it == 4) {
    pair<int, int> pos = start;
    for (int i = 0; instructions[i] != 0; i++) {
      if (instructionmap[instructions[i] - '0'] % 2)
        pos.first += 2 - instructionmap[instructions[i] - '0'];
      else
        pos.second += 1 - instructionmap[instructions[i] - '0'];
      if (pos.first < 0 || pos.second < 0 || pos.first >= m || pos.second >= n)
        return 0;
      if (maze[pos.first][pos.second] == '#') return 0;
      if (maze[pos.first][pos.second] == 'E') return 1;
    }
    return 0;
  } else {
    int ret = 0;
    for (int i = 0; i < 4; i++) {
      if (taken[i]) continue;
      taken[i] = 1;
      instructionmap[it] = i;
      ret += solve(m, n, it + 1);
      taken[i] = 0;
    }
    return ret;
  }
}
int main() {
  int m, n;
  scanf("%d %d", &m, &n);
  for (int i = 0; i < m; i++) {
    scanf("%s", &maze[i]);
    for (int j = 0; j < n; j++)
      if (maze[i][j] == 'S') {
        start.first = i;
        start.second = j;
      }
  }
  scanf("%s", instructions);
  printf("%d\n", solve(m, n, 0));
  return 0;
}
