#include <bits/stdc++.h>
using namespace std;
bool isValidMove(string rule, string path, char **maze, int n, int m,
                 int starti, int startj, int endi, int endj) {
  int curx = starti, cury = startj;
  for (int i = 0; i < path.size(); i++) {
    int index = int(path[i]) - 48;
    char c = rule[index];
    if (c == 'L')
      curx--;
    else if (c == 'R')
      curx++;
    else if (c == 'U')
      cury--;
    else
      cury++;
    if (curx == endi && cury == endj) return true;
    if (curx >= n || cury >= m || curx < 0 || cury < 0) return false;
    if (maze[curx][cury] == '#') return false;
  }
  return false;
}
int main() {
  int n, m;
  string str;
  cin >> n >> m;
  int starti, startj, endi, endj;
  char **a = new char *[n];
  for (int i = 0; i < n; i++) a[i] = new char[m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'S') {
        starti = i;
        startj = j;
      } else if (a[i][j] == 'E') {
        endi = i;
        endj = j;
      }
    }
  }
  cin >> str;
  int count = 0;
  string moves = "LRUD";
  sort(moves.begin(), moves.end());
  int t = 24;
  while (t--) {
    next_permutation(moves.begin(), moves.end());
    if (isValidMove(moves, str, a, n, m, starti, startj, endi, endj)) count++;
  }
  cout << count;
}
