#include <bits/stdc++.h>
using namespace std;
template <typename T>
void printvec(vector<T>& vec) {
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i] << " ";
  }
  cout << "\n";
}
int n, m;
vector<string> arr;
bool func(pair<int, int> curr) {
  int a = curr.first, b = curr.second;
  if (a < 0 || a >= n || b < 0 || b >= m || arr[a][b] == '#') return false;
  return true;
}
int main() {
  std::ios::sync_with_stdio(false);
  int ttt = 1;
  while (ttt--) {
    int i, j;
    int ans = 0;
    cin >> n >> m;
    arr.resize(n);
    for (i = 0; i < n; i++) {
      cin >> arr[i];
    }
    string str;
    cin >> str;
    pair<int, int> start, end;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (arr[i][j] == 'S') start = make_pair(i, j);
        if (arr[i][j] == 'E') end = make_pair(i, j);
      }
    }
    int myints[] = {0, 1, 2, 3};
    std::sort(myints, myints + 4);
    while (1) {
      map<int, char> mapp;
      mapp[myints[0]] = 'l';
      mapp[myints[1]] = 'r';
      mapp[myints[2]] = 'u';
      mapp[myints[3]] = 'd';
      pair<int, int> pre = start;
      for (i = 0; i < str.length(); i++) {
        pair<int, int> curr;
        if (mapp[str[i] - '0'] == 'l')
          curr = make_pair(pre.first, pre.second - 1);
        else if (mapp[str[i] - '0'] == 'r')
          curr = make_pair(pre.first, pre.second + 1);
        else if (mapp[str[i] - '0'] == 'u')
          curr = make_pair(pre.first - 1, pre.second);
        else if (mapp[str[i] - '0'] == 'd')
          curr = make_pair(pre.first + 1, pre.second);
        if (curr == end) {
          ans++;
          break;
        }
        if (!func(curr)) break;
        pre = curr;
      }
      bool abc = std::next_permutation(myints, myints + 4);
      if (!abc) break;
    }
    cout << ans;
  }
  return 0;
}
