#include <bits/stdc++.h>
using namespace std;
void affiche(int t[], int n) {
  for (int i = 0; i < n; i++) cout << t[i] << " ";
  cout << '\n';
}
void afficheV(vector<int> t) {
  for (int i = 0; i < t.size(); i++) cout << t[i] << " ";
}
int n, m;
char t[100][100];
string path;
bool valid(int x, int y, int i) {
  return x >= 0 && x < n && y >= 0 && y < m && i <= path.size();
}
bool solve(int x, int y, int i, int l, int r, int d, int u) {
  if (!valid(x, y, i) or t[x][y] == '#') return false;
  if (t[x][y] == 'E') return true;
  if (path[i] == l + '0') return solve(x - 1, y, i + 1, l, r, d, u);
  if (path[i] == r + '0') return solve(x + 1, y, i + 1, l, r, d, u);
  if (path[i] == d + '0') return solve(x, y + 1, i + 1, l, r, d, u);
  if (path[i] == u + '0') return solve(x, y - 1, i + 1, l, r, d, u);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  int xs, ys;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> t[i][j];
      if (t[i][j] == 'S') xs = i, ys = j;
    }
  int ans = 0;
  cin >> path;
  for (int l = 0; l < 4; l++)
    for (int r = 0; r < 4; r++)
      for (int d = 0; d < 4; d++)
        for (int u = 0; u < 4; u++) {
          if (l == r or l == d or l == u or r == d or r == u or d == u)
            continue;
          ans += solve(xs, ys, 0, l, r, d, u);
        }
  cout << ans;
}
