#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if ((a == 0) || (b == 0)) return a + b;
  return gcd(b, a % b);
}
long long pow_mod(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
bool isPrime(long long a) {
  for (int i = 3; (i * i) <= a; i += 2) {
    if ((a % i) == 0) {
      return false;
    }
  }
  return true;
}
long long N, M;
string st[200], st2;
pair<long long, long long> prio[10], star, endd;
map<char, long long> ma;
vector<string> vc;
bool check(long long X, long long Y) {
  if (X <= 0 || Y <= 0 || X > N || Y > M) return 0;
  if (st[X][Y] == '#') return 0;
  return 1;
}
void func(string st, int l, int r) {
  if (l == r) {
    vc.push_back(st);
    return;
  }
  for (int i = l; i <= r; i++) {
    swap(st[l], st[i]);
    func(st, l + 1, r);
    swap(st[i], st[l]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long i, j, ans = 0;
  prio[0] = make_pair(-1, 0);
  prio[1] = make_pair(1, 0);
  prio[2] = make_pair(0, 1);
  prio[3] = make_pair(0, -1);
  func("0123", 0, 3);
  cin >> N >> M;
  for (i = 1; i <= N; i++) {
    cin >> st[i];
    st[i] = "#" + st[i];
  }
  cin >> st2;
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= (int)st[i].length() - 1; j++) {
      if (st[i][j] == 'S') {
        star = make_pair(i, j);
      } else if (st[i][j] == 'E') {
        endd = make_pair(i, j);
      }
    }
  }
  for (i = 0; i <= 23; i++) {
    long long pp = 0;
    for (j = 0; j <= (int)vc[i].length() - 1; j++) {
      ma[vc[i][j]] = pp++;
    }
    pair<long long, long long> opop = star;
    for (j = 0; j <= (int)st2.length() - 1; j++) {
      long long val = ma[st2[j]];
      long long xx = opop.first + prio[val].first;
      long long yy = opop.second + prio[val].second;
      if (!check(xx, yy)) {
        break;
      }
      if (make_pair(xx, yy) == endd) {
        ans++;
        break;
      }
      opop = make_pair(xx, yy);
    }
  }
  cout << ans;
  return 0;
}
