#include <bits/stdc++.h>
using namespace std;
const int maxn = 60;
const long long inf = 1e18 + 43;
const long long mod = 1e9 + 7;
const int maxlog = 20;
string s[maxn];
int n, m;
string t;
int sx, sy, fx, fy;
bool check(vector<char> v) {
  int x = sx, y = sy;
  for (int i = 0; i < t.size(); i++) {
    int cur = t[i] - '0';
    if (v[cur] == 'U')
      x--;
    else if (v[cur] == 'D')
      x++;
    else if (v[cur] == 'L')
      y--;
    else if (v[cur] == 'R')
      y++;
    bool ok = false;
    if (x >= 0 && y >= 0 && x < n && y < m && s[x][y] != '#') ok = true;
    if (x == fx && y == fy) return true;
    if (!ok) return false;
  }
  if (x == fx && y == fy) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(20);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  cin >> t;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'S') {
        sx = i;
        sy = j;
      }
      if (s[i][j] == 'E') {
        fx = i;
        fy = j;
      }
    }
  }
  vector<char> v;
  v.push_back('U');
  v.push_back('L');
  v.push_back('D');
  v.push_back('R');
  sort(v.begin(), v.end());
  int ans = 0;
  if (check(v)) ans++;
  while (next_permutation(v.begin(), v.end())) {
    if (check(v)) ans++;
  }
  cout << ans;
  return 0;
}
