#include <bits/stdc++.h>
using namespace std;
char c[100][100];
pair<int, int> x[4], v[4] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string second;
  int n, m, an = 0, s1, s2;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
      if (c[i][j] == 'S') {
        s1 = i;
        s2 = j;
      }
    }
  cin >> second;
  for (int i = 0; i < 4; i++) {
    x[0] = v[i];
    for (int j = 0; j < 4; j++) {
      if (i == j) continue;
      x[1] = v[j];
      for (int k = 0; k < 4; k++) {
        if (k == i || k == j) continue;
        x[2] = v[k];
        for (int u = 0; u < 4; u++) {
          if (u == k || u == i || u == j) continue;
          x[3] = v[u];
          pair<int, int> p = {s1, s2};
          for (int q = 0; q < second.size(); q++) {
            p.first += x[second[q] - '0'].first;
            p.second += x[second[q] - '0'].second;
            if (p.first >= n || p.first < 0 || p.second >= m || p.second < 0 ||
                c[p.first][p.second] == '#')
              break;
            if (c[p.first][p.second] == 'E') {
              an++;
              break;
            }
          }
        }
      }
    }
  }
  cout << an;
  return 0;
}
