#include <bits/stdc++.h>
using namespace std;
int n, m;
string s[65], t;
int sx, sy, ex, ey;
bool can(int a, int b, int c, int d) {
  int fun[4];
  fun[0] = a;
  fun[1] = b;
  fun[2] = c;
  fun[3] = d;
  int nx = sx, ny = sy, px = sx, py = sy;
  for (int i = 0; i <= t.length(); i++) {
    int ps;
    if (i != t.length()) ps = fun[t[i] - '0'];
    px = nx;
    py = ny;
    if (nx > n - 1 || ny > m - 1 || nx < 0 || ny < 0 || s[px][py] == '#')
      return false;
    if (s[px][py] == 'E') return true;
    if (i == t.length()) return false;
    if (ps == 0) {
      ny = py - 1;
    }
    if (ps == 1) {
      ny = py + 1;
    }
    if (ps == 2) {
      nx = px - 1;
    }
    if (ps == 3) nx = px + 1;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'S') {
        sx = i;
        sy = j;
      }
      if (s[i][j] == 'E') {
        ex = i;
        ey = j;
      }
    }
  }
  cin >> t;
  int yes = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (i == j) continue;
      for (int k = 0; k < 4; k++) {
        if (k == j || k == i) continue;
        for (int l = 0; l < 4; l++) {
          if (l == k || l == j || l == i) continue;
          if (can(i, j, k, l)) yes++;
        }
      }
    }
  }
  cout << yes;
}
