#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, res = 0, row, col, num = 0;
char a[100][100];
string s;
bool valid(int x, int y) {
  if (x > -1 && x < n && y > -1 && y < m && a[x][y] != '#') return true;
  return false;
}
string h = "0123";
vector<string> vs;
int main() {
  ios_base::sync_with_stdio(false);
  do {
    vs.push_back(h);
  } while (next_permutation(h.begin(), h.end()));
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'S') row = i, col = j;
    }
  }
  cin >> s;
  for (int i = 0; i < vs.size(); i++) {
    res = 0;
    int x = row, y = col;
    for (int j = 0; j < s.size(); j++) {
      if (a[x][y] == 'E') {
        break;
      }
      if (s[j] == vs[i][0]) {
        if (valid(x + 1, y))
          x++;
        else
          break;
      } else if (s[j] == vs[i][1]) {
        if (valid(x, y - 1))
          y--;
        else
          break;
      } else if (s[j] == vs[i][2]) {
        if (valid(x - 1, y))
          x--;
        else
          break;
      } else if (s[j] == vs[i][3]) {
        if (valid(x, y + 1))
          y++;
        else
          break;
      }
      res++;
    }
    if (a[x][y] == 'E') num++;
  }
  cout << num;
  return 0;
}
