#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MAX = 111;
string A[MAX];
pair<int, int> d[4] = {make_pair(0, 1), make_pair(0, -1), make_pair(1, 0),
                       make_pair(-1, 0)};
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = (0); i < (n); i++) {
    cin >> A[i];
  }
  int x1, y1;
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < (m); j++) {
      if (A[i][j] == 'S') {
        x1 = i;
        y1 = j;
      }
    }
  }
  string s;
  cin >> s;
  int res = 0;
  sort(d, d + 4);
  do {
    int x = x1, y = y1;
    bool ok = false;
    for (int i = (0); i < ((int)s.size()); i++) {
      int dx = d[s[i] - '0'].first;
      int dy = d[s[i] - '0'].second;
      x += dx;
      y += dy;
      if (x < 0 || y < 0 || x >= n || y >= m) {
        ok = false;
        break;
      }
      if (A[x][y] == '#') {
        ok = false;
        break;
      }
      if (A[x][y] == 'E') {
        ok = true;
        break;
      }
    }
    res += ok;
  } while (next_permutation(d, d + 4));
  cout << res << endl;
}
