#include <bits/stdc++.h>
using namespace std;
int n, m, sx, sy;
char a[60][60];
string s;
vector<int> vt;
int slv() {
  int x = sx, y = sy;
  for (int i = 0; i < s.size(); i++) {
    int nw = s[i] - 48;
    if (vt[0] == nw) y--;
    if (vt[1] == nw) x--;
    if (vt[2] == nw) y++;
    if (vt[3] == nw) x++;
    if (x < 1 || y < 1 || x > n || y > m) return 0;
    if (a[x][y] == '#') return 0;
    if (a[x][y] == 'E') return 1;
  }
  return 0;
}
int main() {
  ios_base::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 >> a[i][j];
      if (a[i][j] == 'S') {
        sx = i;
        sy = j;
      }
    }
  cin >> s;
  int res = 0;
  for (int i = 0; i < 4; i++) vt.push_back(i);
  do {
    res += slv();
  } while (next_permutation(vt.begin(), vt.end()));
  cout << res;
  return 0;
}
