#include <bits/stdc++.h>
using namespace std;
bool check(vector<string> &s, vector<char> &ch, string &moves) {
  long long x = -1, y = 0, n = s.size(), m = s[0].size();
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++)
      if (s[i][j] == 'S') {
        x = i;
        y = j;
        break;
      }
    if (x != -1) break;
  }
  long long len = moves.size();
  for (long long i = 0; i < len; i++) {
    if (moves[i] == ch[0]) {
      x--;
    }
    if (moves[i] == ch[1]) {
      x++;
    }
    if (moves[i] == ch[2]) {
      y--;
    }
    if (moves[i] == ch[3]) {
      y++;
    }
    if (x >= n || x < 0 || y >= m || y < 0 || s[x][y] == '#') return false;
    if (s[x][y] == 'E') return true;
  }
  return false;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<string> s(n);
  string moves;
  for (auto &i : s) cin >> i;
  cin >> moves;
  vector<char> ch = {'0', '1', '2', '3'};
  long long cnt = 0;
  do {
    if (check(s, ch, moves)) cnt++;
  } while (next_permutation(ch.begin(), ch.end()));
  cout << cnt;
  return 0;
}
