#include <bits/stdc++.h>
using namespace std;
string s;
long int k, startI, startJ, summ, n, m;
char a[1000][1000];
int checker(int l, int r, int t, int b) {
  int nowI = startI;
  int nowJ = startJ;
  if (l == r || l == t || l == b || r == t || r == b || t == b) {
    return 0;
  }
  for (int i = 0; i < s.size(); i++) {
    if ((int)s[i] - (int)'0' == l) {
      nowI -= 1;
    } else if ((int)s[i] - (int)'0' == r) {
      nowI += 1;
    } else if ((int)s[i] - (int)'0' == t) {
      nowJ -= 1;
    } else if ((int)s[i] - (int)'0' == b) {
      nowJ += 1;
    }
    if (a[nowI][nowJ] == '#' || nowI < 0 || nowI >= n || nowJ < 0 ||
        nowJ >= m) {
      return 0;
    } else if (a[nowI][nowJ] == 'E') {
      return 1;
    }
  }
  return 0;
}
int main() {
  cin >> n >> m;
  getline(cin, s);
  for (int i = 0; i < n; i++) {
    getline(cin, s);
    for (int j = 0; j < m; j++) {
      a[i][j] = s[j];
      if (a[i][j] == 'S') {
        startI = i;
        startJ = j;
      }
    }
  }
  getline(cin, s);
  summ = 0;
  for (int ii = 0; ii <= 3; ii++) {
    for (int j = 0; j <= 3; j++) {
      for (int k = 0; k <= 3; k++) {
        for (int l = 0; l <= 3; l++) {
          if (checker(ii, j, k, l)) {
            summ++;
          }
        }
      }
    }
  }
  cout << summ;
}
