#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
bool Max(T1& a, T2 b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T1, typename T2>
bool Min(T1& a, T2 b) {
  return a > b ? a = b, 1 : 0;
}
const int N = 51;
char a[N][N];
void solve() {
  int n, m;
  cin >> n >> m;
  int si, sj;
  string cmd;
  for (int i = 0; i < (int)(n); ++i)
    for (int j = 0; j < (int)(m); ++j) {
      cin >> a[i][j];
      if (a[i][j] == 'S') si = i, sj = j;
    }
  cin >> cmd;
  for (auto& ch : cmd) ch -= '0';
  int dir[4] = {0, 1, 2, 3};
  int dx[4] = {-1, 0, 1, 0};
  int dy[4] = {0, 1, 0, -1};
  int ans = 0;
  do {
    int ci = si, cj = sj;
    for (auto& ch : cmd) {
      ci += dx[dir[ch]];
      cj += dy[dir[ch]];
      if (ci < 0 || cj < 0 || ci == n || cj == m || a[ci][cj] == '#') break;
      if (a[ci][cj] == 'E') {
        ans++;
        break;
      }
    }
  } while (next_permutation(dir, dir + 4));
  cout << ans << '\n';
}
void init() {}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  init();
  int TC = 1;
  for (int TI = 1; TI <= (int)(TC); ++TI) {
    solve();
  }
  return 0;
}
