#include <bits/stdc++.h>
using namespace std;
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  fast();
  string str = "DLRU";
  int n, m;
  cin >> n >> m;
  vector<vector<char>> maze(n, vector<char>(m));
  int si = 0, sj = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> maze[i][j];
      if (maze[i][j] == 'S') si = i, sj = j;
    }
  string order;
  cin >> order;
  int ans = 0;
  map<char, char> direction;
  do {
    direction.clear();
    for (int i = 0; i <= 3; i++) direction[char(i + '0')] = str[i];
    int curi = si, curj = sj;
    for (auto i : order) {
      if (direction[i] == 'D')
        curi++;
      else if (direction[i] == 'L')
        curj--;
      else if (direction[i] == 'R')
        curj++;
      else if (direction[i] == 'U')
        curi--;
      if (curi >= n || curj >= m || curi < 0 || curj < 0) break;
      if (maze[curi][curj] == '#') break;
      if (maze[curi][curj] == 'E') {
        ans++;
        break;
      }
    }
  } while (next_permutation(str.begin(), str.end()));
  cout << ans << endl;
  return 0;
}
