#include <bits/stdc++.h>
using namespace std;
int n, m, xx, yy;
string mm[55], s;
int nx[4] = {-1, 0, 1, 0};
int ny[4] = {0, 1, 0, -1};
int perm[4] = {0, 1, 2, 3};
bool canGo(int x, int y) {
  return x >= 0 && x < n && y >= 0 && y < m && mm[x][y] != '#';
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> mm[i];
  cin >> s;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (mm[i][j] == 'S') {
        xx = i;
        yy = j;
        break;
      }
  int ans = 0;
  do {
    int x = xx, y = yy;
    for (int i = 0; i < s.length(); ++i) {
      int cur = perm[(int)(s[i] - '0')];
      x = x + nx[cur];
      y = y + ny[cur];
      if (!canGo(x, y)) break;
      if (mm[x][y] == 'E') {
        ++ans;
        break;
      }
    }
  } while (next_permutation(perm, perm + 4));
  cout << ans << endl;
  return 0;
}
