#include <bits/stdc++.h>
using namespace std;
int solve(vector<vector<char>> mat, int n, int m, string dir,
          pair<int, int> s) {
  string name = "DLRU";
  int count = 0;
  int len = dir.length();
  map<char, char> mp;
  while (true) {
    mp['0'] = name[0];
    mp['1'] = name[1];
    mp['2'] = name[2];
    mp['3'] = name[3];
    int parse = 0;
    int i = s.first;
    int j = s.second;
    while (true) {
      if (parse == len) break;
      char ch = mp[dir[parse++]];
      if (ch == 'L') {
        j = j - 1;
        if (j < 0) break;
      } else if (ch == 'R') {
        j = j + 1;
        if (j >= m) break;
      } else if (ch == 'U') {
        i = i - 1;
        if (i < 0) break;
      } else {
        i = i + 1;
        if (i >= n) break;
      }
      if (mat[i][j] == 'E') {
        count++;
        break;
      }
      if (mat[i][j] == '#') break;
    }
    if (!next_permutation(name.begin(), name.end())) break;
  }
  return count;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<char>> mat(n, vector<char>(m));
  string name, dir;
  pair<int, int> s;
  for (int i = 0; i < n; i++) {
    cin >> name;
    for (int j = 0; j < m; j++) {
      if (name[j] == 'S') {
        s = make_pair(i, j);
      }
      mat[i][j] = name[j];
    }
  }
  cin >> dir;
  cout << solve(mat, n, m, dir, s) << endl;
  return 0;
}
