#include <bits/stdc++.h>
using namespace std;
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\n';
  err(++it, args...);
}
long long int valid(vector<string> board, vector<long long int> conf,
                    string dir) {
  long long int x = -1, y = -1;
  long long int n = board.size(), m = board[0].length();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (board[i][j] == 'S') {
        x = i;
        y = j;
        break;
      }
    }
    if (x != -1) break;
  }
  for (int i = 0; i < dir.length(); i++) {
    if (x < 0 || x >= n) return 0;
    if (y < 0 || y >= m) return 0;
    if (board[x][y] == '#') return 0;
    if (board[x][y] == 'E') return 1;
    long long int p = dir[i] - '0';
    switch (conf[p]) {
      case 0:
        x++;
        break;
      case 1:
        x--;
        break;
      case 2:
        y++;
        break;
      case 3:
        y--;
        break;
    }
  }
  if (x < 0 || x >= n) return 0;
  if (y < 0 || y >= m) return 0;
  if (board[x][y] == '#') return 0;
  if (board[x][y] == 'E') return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  vector<string> board(n);
  for (int i = 0; i < n; i++) cin >> board[i];
  string dir;
  cin >> dir;
  vector<long long int> conf = {0, 1, 2, 3};
  long long int ans = 0;
  do {
    if (valid(board, conf, dir)) ans++;
  } while (next_permutation(conf.begin(), conf.end()));
  cout << ans << endl;
  return 0;
}
