#include <bits/stdc++.h>
using namespace std;
int labirinth[50][50];
int main() {
  int n, m, sx, sy, fx, fy;
  string str;
  cin >> n >> m;
  vector<vector<int> > lab(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    cin >> str;
    for (int j = 0; j < m; j++) {
      if (str[j] == '#') {
        lab[i][j] = 1;
      } else {
        lab[i][j] = 0;
      }
      if (str[j] == 'S') {
        sx = i;
        sy = j;
      } else if (str[j] == 'E') {
        fx = i;
        fy = j;
      }
    }
  }
  cin >> str;
  int amount_of_commands = str.size();
  vector<int> commands(amount_of_commands);
  for (int i = 0; i < amount_of_commands; i++) {
    commands[i] = str[i] - '0';
  }
  int ans = 0;
  bool proof;
  int x, y;
  int dp[] = {0, 1, 2, 3};
  do {
    x = sx;
    y = sy;
    proof = false;
    for (int i = 0; i < amount_of_commands; i++) {
      if (dp[commands[i]] == 0) {
        x--;
      } else if (dp[commands[i]] == 1) {
        y--;
      } else if (dp[commands[i]] == 2) {
        x++;
      } else {
        y++;
      }
      if ((0 > x) || (x >= n) || (0 > y) || (y >= m) || (lab[x][y] == 1)) {
        proof = false;
        break;
      }
      if ((x == fx) && (y == fy)) {
        proof = true;
        break;
      }
    }
    if (proof) {
      ans++;
    }
  } while (next_permutation(dp, dp + 4));
  cout << ans;
  return 0;
}
