#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<char> empty(m);
  vector<vector<char>> a(n, empty);
  int x, y;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
      if (a[i][j] == 'S') {
        x = i;
        y = j;
      }
    }
  }
  string check;
  cin >> check;
  vector<char> p(4);
  p[0] = 'u';
  p[1] = 'r';
  p[2] = 'd';
  p[3] = 'l';
  sort(p.begin(), p.end());
  int cnt = 0;
  do {
    int f = x, s = y;
    for (int i = 0; i < check.length(); ++i) {
      if (p[(int)(check[i] - '0')] == 'u') {
        if (f > 0) {
          f--;
        } else {
          break;
        }
      }
      if (p[(int)(check[i] - '0')] == 'r') {
        if (s < m - 1) {
          s++;
        } else {
          break;
        }
      }
      if (p[(int)(check[i] - '0')] == 'd') {
        if (f < n - 1) {
          f++;
        } else {
          break;
        }
      }
      if (p[(int)(check[i] - '0')] == 'l') {
        if (s > 0) {
          s--;
        } else {
          break;
        }
      }
      if (a[f][s] == 'E') {
        cnt++;
        break;
      }
      if (a[f][s] == '#') {
        break;
      }
    }
  } while (next_permutation(p.begin(), p.end()));
  cout << cnt;
}
