#include <bits/stdc++.h>
using namespace std;
struct dir {
  long long L, R, U, D;
} lnk[30];
void init() {
  long long i = 1;
  lnk[i].L = 0, lnk[i].R = 1, lnk[i].U = 2, lnk[i].D = 3, i++;
  lnk[i].L = 0, lnk[i].R = 1, lnk[i].U = 3, lnk[i].D = 2, i++;
  lnk[i].L = 0, lnk[i].R = 2, lnk[i].U = 1, lnk[i].D = 3, i++;
  lnk[i].L = 0, lnk[i].R = 2, lnk[i].U = 3, lnk[i].D = 1, i++;
  lnk[i].L = 0, lnk[i].R = 3, lnk[i].U = 1, lnk[i].D = 2, i++;
  lnk[i].L = 0, lnk[i].R = 3, lnk[i].U = 2, lnk[i].D = 1, i++;
  i = 7;
  lnk[i].L = 1, lnk[i].R = 0, lnk[i].U = 2, lnk[i].D = 3, i++;
  lnk[i].L = 1, lnk[i].R = 0, lnk[i].U = 3, lnk[i].D = 2, i++;
  lnk[i].L = 1, lnk[i].R = 2, lnk[i].U = 0, lnk[i].D = 3, i++;
  lnk[i].L = 1, lnk[i].R = 2, lnk[i].U = 3, lnk[i].D = 0, i++;
  lnk[i].L = 1, lnk[i].R = 3, lnk[i].U = 0, lnk[i].D = 2, i++;
  lnk[i].L = 1, lnk[i].R = 3, lnk[i].U = 2, lnk[i].D = 0, i++;
  i = 13;
  lnk[i].L = 2, lnk[i].R = 0, lnk[i].U = 1, lnk[i].D = 3, i++;
  lnk[i].L = 2, lnk[i].R = 0, lnk[i].U = 3, lnk[i].D = 1, i++;
  lnk[i].L = 2, lnk[i].R = 1, lnk[i].U = 0, lnk[i].D = 3, i++;
  lnk[i].L = 2, lnk[i].R = 1, lnk[i].U = 3, lnk[i].D = 0, i++;
  lnk[i].L = 2, lnk[i].R = 3, lnk[i].U = 0, lnk[i].D = 1, i++;
  lnk[i].L = 2, lnk[i].R = 3, lnk[i].U = 1, lnk[i].D = 0, i++;
  i = 19;
  lnk[i].L = 3, lnk[i].R = 0, lnk[i].U = 1, lnk[i].D = 2, i++;
  lnk[i].L = 3, lnk[i].R = 0, lnk[i].U = 2, lnk[i].D = 1, i++;
  lnk[i].L = 3, lnk[i].R = 1, lnk[i].U = 0, lnk[i].D = 2, i++;
  lnk[i].L = 3, lnk[i].R = 1, lnk[i].U = 2, lnk[i].D = 0, i++;
  lnk[i].L = 3, lnk[i].R = 2, lnk[i].U = 0, lnk[i].D = 1, i++;
  lnk[i].L = 3, lnk[i].R = 2, lnk[i].U = 1, lnk[i].D = 0, i++;
}
string graph[55], ins;
long long row, col, sx, sy, ex, ey;
bool check(long long idx) {
  long long x = sx, y = sy;
  for (long long i = 0; ins[i]; i++) {
    long long dx = ins[i] - '0';
    if (lnk[idx].L == dx)
      y--;
    else if (lnk[idx].R == dx)
      y++;
    else if (lnk[idx].U == dx)
      x--;
    else if (lnk[idx].D == dx)
      x++;
    if ((x < 0 || x >= row) || (y < 0 || y >= col) || graph[x][y] == '#')
      return false;
    if (x == ex && y == ey) return true;
  }
  return false;
}
int main() {
  init();
  while (cin >> row >> col) {
    for (long long i = 0; i < row; i++) cin >> graph[i];
    cin >> ins;
    for (long long i = 0; i < row; i++) {
      for (long long j = 0; j < col; j++) {
        if (graph[i][j] == 'S') {
          sx = i, sy = j;
        }
        if (graph[i][j] == 'E') {
          ex = i, ey = j;
        }
      }
    }
    long long comb = 0;
    for (long long i = 1; i <= 24; i++) {
      if (check(i)) comb++;
    }
    cout << comb << endl;
  }
  return 0;
}
