#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
string s[maxn];
pair<int, int> mov[] = {pair<int, int>(-1, 0), pair<int, int>(0, 1),
                        pair<int, int>(0, -1), pair<int, int>(1, 0)};
bool checkPath(int n, int m, pair<int, int> st, pair<int, int> ed,
               string path) {
  for (char c : path) {
    int idx = c - '0';
    st.first += mov[idx].first;
    st.second += mov[idx].second;
    if (st.first < 0 || st.first >= n) {
      return false;
    }
    if (st.second < 0 || st.second >= m) {
      return false;
    }
    if (s[st.first][st.second] == '#') {
      return false;
    }
    if (st == ed) {
      return true;
    }
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  cin.ignore();
  pair<int, int> st, ed;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'S') {
        st = pair<int, int>(i, j);
        s[i][j] = '.';
      }
      if (s[i][j] == 'E') {
        ed = pair<int, int>(i, j);
        s[i][j] = '.';
      }
    }
  }
  string path;
  cin >> path;
  sort(mov, mov + 4);
  int ans = 0;
  int it = 0;
  do {
    if (checkPath(n, m, st, ed, path)) {
      ans++;
    }
  } while (next_permutation(mov, mov + 4));
  cout << ans << endl;
  return 0;
}
