#include <bits/stdc++.h>
using namespace std;
int main() {
  int s[] = {0, 1, 2, 3};
  int n, m, count, ci, cj, si, sj, i, j;
  char l, r, u, d;
  string st;
  cin >> n >> m;
  char A[n][m];
  char c;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> c;
      A[i][j] = c;
      if (c == 'S') {
        si = i;
        sj = j;
      }
    }
  }
  cin >> st;
  count = 0;
  do {
    l = s[0] + '0', r = s[1] + '0', u = s[2] + '0', d = s[3] + '0';
    ci = si;
    cj = sj;
    for (i = 0; i < st.size(); i++) {
      if (st[i] == l) {
        if (cj >= 1 && A[ci][cj - 1] != '#') {
          if (A[ci][cj - 1] == 'E') {
            count++;
            break;
          }
          cj = cj - 1;
        } else {
          break;
        }
      } else if (st[i] == r) {
        if (cj < (m - 1) && A[ci][cj + 1] != '#') {
          if (A[ci][cj + 1] == 'E') {
            count++;
            break;
          }
          cj = cj + 1;
        } else {
          break;
        }
      } else if (st[i] == u) {
        if (ci > 0 && A[ci - 1][cj] != '#') {
          if (A[ci - 1][cj] == 'E') {
            count++;
            break;
          }
          ci = ci - 1;
        } else {
          break;
        }
      } else {
        if (ci < (n - 1) && A[ci + 1][cj] != '#') {
          if (A[ci + 1][cj] == 'E') {
            count++;
            break;
          }
          ci = ci + 1;
        } else {
          break;
        }
      }
    }
  } while (next_permutation(s, s + 4));
  cout << count;
  return 0;
}
