#include <bits/stdc++.h>
using namespace std;
char mmap[100][100];
const int MAXN = 1e5 + 100;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  int sx, sy, ex, ey;
  string call;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> mmap[i][j];
      if (mmap[i][j] == 'S') {
        sx = i;
        sy = j;
      }
      if (mmap[i][j] == 'E') {
        ex = i;
        ey = j;
      }
    }
  int x = sx, y = sy;
  cin >> call;
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++)
      for (int k = 0; k < 4; k++)
        for (int l = 0; l < 4; l++) {
          if (i == j || j == k || i == k || k == l || i == l || j == l ||
              i + l + j + k != 6)
            continue;
          else {
            sx = x;
            sy = y;
            for (int t = 0; t < call.size(); t++) {
              int tmp = call[t] - '0';
              if (tmp == i) {
                sy += 1;
              } else if (tmp == j) {
                sy -= 1;
              } else if (tmp == k) {
                sx -= 1;
              } else if (tmp == l) {
                sx += 1;
              }
              if (sx == 0 || sy == 0 || sx > n || sy > m || mmap[sx][sy] == '#')
                break;
              if (sx == ex && sy == ey) {
                ans++;
                break;
              }
            }
          }
        }
  }
  cout << ans << endl;
  return 0;
}
