#include <bits/stdc++.h>
using namespace std;
int n, m;
const int size = 55;
bool wall[size][size];
bool odw[size][size];
char c;
pair<int, int> S, E;
int dy[] = {0, 0, -1, 1};
int dx[] = {1, -1, 0, 0};
int ma[] = {0, 1, 2, 3};
string instr;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      cin >> c;
      if (c == 'S')
        S = {i, j};
      else if (c == 'E')
        E = {i, j};
      wall[i][j] = c == '#';
    }
  for (int j = 1; j <= m; ++j) wall[0][j] = wall[n + 1][j] = 1;
  for (int i = 1; i <= n; ++i) wall[i][0] = wall[i][m + 1] = 1;
  cin >> instr;
  int cnt = 0;
  do {
    pair<int, int> kord = S;
    for (char second : instr) {
      int inst = ma[second - '0'];
      pair<int, int> nowy = {kord.first + dy[inst], kord.second + dx[inst]};
      if (wall[nowy.first][nowy.second]) break;
      if (nowy == E) {
        ++cnt;
        break;
      }
      kord = nowy;
    }
  } while (next_permutation(ma, ma + 4));
  cout << cnt;
  return 0;
}
