#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
int n, m;
char c[60][60];
bool inBounds(int x, int y) {
  return x < n && x >= 0 && y < m && y >= 0 && c[x][y] != '#';
}
int main() {
  ios::sync_with_stdio(false);
  int sx, sy, ex, ey;
  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') {
        sx = i;
        sy = j;
      } else if (c[i][j] == 'E') {
        ex = i;
        ey = j;
      }
    }
  }
  string s;
  cin >> s;
  int a[4] = {0, 1, 2, 3};
  int ans = 0;
  for (int i = 0; i < 24; i++) {
    unordered_map<int, char> m;
    m[a[0]] = 'u';
    m[a[1]] = 'l';
    m[a[2]] = 'd';
    m[a[3]] = 'r';
    bool b = 0;
    int cx = sx, cy = sy;
    for (int j = 0; j < s.size(); j++) {
      if (m[s[j] - '0'] == 'u') {
        if (inBounds(cx - 1, cy)) {
          cx--;
        } else {
          b = 1;
          break;
        }
      } else if (m[s[j] - '0'] == 'l') {
        if (inBounds(cx, cy - 1)) {
          cy--;
        } else {
          b = 1;
          break;
        }
      } else if (m[s[j] - '0'] == 'd') {
        if (inBounds(cx + 1, cy)) {
          cx++;
        } else {
          b = 1;
          break;
        }
      } else if (m[s[j] - '0'] == 'r') {
        if (inBounds(cx, cy + 1)) {
          cy++;
        } else {
          b = 1;
          break;
        }
      }
      if (cx == ex && cy == ey) {
        ans++;
        break;
      }
    }
    next_permutation(a, a + 4);
  }
  cout << ans;
  return 0;
}
