#include <bits/stdc++.h>
using namespace std;
int n, m;
int xs, ys, xe, ye;
string s[55];
string way;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> s[i], s[i] = '0' + s[i] + '0';
  cin >> way;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == 'S') xs = i, ys = j;
      if (s[i][j] == 'E') xe = i, ye = j;
    }
  }
  int ans = 0;
  vector<int> perm;
  for (int i = 0; i < 4; i++) perm.push_back(i);
  do {
    int tx = xs, ty = ys;
    for (int i = 0; i < (int)way.size(); i++) {
      if (perm[way[i] - '0'] == 0) tx--;
      if (perm[way[i] - '0'] == 1) tx++;
      if (perm[way[i] - '0'] == 2) ty--;
      if (perm[way[i] - '0'] == 3) ty++;
      if (tx < 1 || n < tx) break;
      if (ty < 1 || m < ty) break;
      if (s[tx][ty] == '#') break;
      if (s[tx][ty] == 'E') {
        ans++;
        break;
      }
    }
  } while (next_permutation(perm.begin(), perm.end()));
  cout << ans;
}
