#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string g[n], s;
  int sx, sy, ex, ey;
  for (int i = 0; i < n; i++) {
    cin >> g[i];
    for (int j = 0; j < m; j++) {
      if (g[i][j] == 'S') {
        sx = i;
        sy = j;
      } else if (g[i][j] == 'E') {
        ex = i;
        ey = j;
      }
    }
  }
  cin >> s;
  vector<int> v;
  v.push_back(0);
  v.push_back(1);
  v.push_back(2);
  v.push_back(3);
  int idx[] = {0, 0, 1, -1};
  int idy[] = {1, -1, 0, 0};
  int ans = 0;
  do {
    int x = sx, y = sy;
    for (int i = 0; i < s.size(); i++) {
      x += idx[v[s[i] - '0']];
      y += idy[v[s[i] - '0']];
      if (x < 0 || x > n - 1 || y < 0 || y > m - 1 || g[x][y] == '#') break;
      if (g[x][y] == 'E') {
        ans++;
        break;
      }
    }
  } while (next_permutation(v.begin(), v.end()));
  cout << ans;
  return 0;
}
