#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
};
int to[4][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
int N, M;
int mapDir[4];
int cnt = 0;
char path[105];
char grid[105][105];
node s, e;
int ans = 0;
bool canExit(node s, node e) {
  int len = strlen(path);
  node now;
  now.x = s.x;
  now.y = s.y;
  for (int i = 0; i < len; i++) {
    now.x = now.x + to[mapDir[path[i] - '0']][0];
    now.y = now.y + to[mapDir[path[i] - '0']][1];
    if (now.x == e.x && now.y == e.y) {
      return true;
    } else if (grid[now.x][now.y] == '#') {
      return false;
    } else if (now.x < 0 || now.y < 0 || now.x >= N || now.y >= M) {
      return false;
    }
  }
  return false;
}
void dfs() {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (j == i) {
        continue;
      }
      for (int k = 0; k < 4; k++) {
        if (k == i || k == j) {
          continue;
        }
        for (int p = 0; p < 4; p++) {
          if (i == p || j == p || k == p) {
            continue;
          }
          mapDir[0] = i;
          mapDir[1] = j;
          mapDir[2] = k;
          mapDir[3] = p;
          if (canExit(s, e)) {
            ans++;
          }
        }
      }
    }
  }
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    scanf("%s", grid[i]);
    for (int j = 0; j < M; j++) {
      if (grid[i][j] == 'S') {
        s.x = i;
        s.y = j;
      }
      if (grid[i][j] == 'E') {
        e.x = i;
        e.y = j;
      }
    }
  }
  scanf("%s", path);
  ans = 0;
  dfs();
  printf("%d\n", ans);
  return 0;
}
