#include <bits/stdc++.h>
using namespace std;
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < v.size(); i++) is >> v[i];
  return is;
}
template <class T>
ostream &operator<<(ostream &os, vector<T> v) {
  for (int i = 0; i < v.size(); i++) os << v[i] << ' ';
  os << '\n';
  return os;
}
const int BASE = 1e+9 + 7;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  pair<int, int> st, fn;
  vector<vector<bool>> w(n, vector<bool>(m, false));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (s[j] == '#')
        w[i][j] = true;
      else if (s[j] == 'S')
        st = {i, j};
      else if (s[j] == 'E')
        fn = {i, j};
    }
  }
  string s;
  cin >> s;
  vector<int> type(4);
  type[0] = 0, type[1] = 1, type[2] = 2, type[3] = 3;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) s[i] -= '0';
  for (int k = 0; k < 4 * 3 * 2 * 1; k++) {
    bool end = false;
    int i = st.first, j = st.second;
    for (int t = 0; t < s.size() && !end; t++) {
      if (s[t] == type[0])
        i--;
      else if (s[t] == type[1])
        i++;
      else if (s[t] == type[2])
        j--;
      else if (s[t] == type[3])
        j++;
      if (i < 0 || i >= n || j < 0 || j >= m || w[i][j]) break;
      if (i == fn.first && j == fn.second) end = true;
    }
    cnt += end;
    next_permutation(type.begin(), type.end());
  }
  std::cout << cnt;
}
