#include <bits/stdc++.h>
using namespace std;
template <typename T>
void Read(T &x) {
  char ch;
  bool neg = 0;
  x = 0;
  while (!isdigit(ch = getchar()) && ch != '-')
    ;
  if (ch == '-') {
    neg = 1;
    ch = getchar();
  }
  do {
    x = x * 10 + ch - 48;
  } while (isdigit(ch = getchar()));
  if (neg) x = -x;
  return;
}
template <typename T>
void Write(T x) {
  char ch[32];
  int cnt = 0;
  bool neg = 0;
  if (x < 0) {
    neg = 1;
    x = -x;
  }
  do {
    ch[++cnt] = x % 10 + 48;
    x /= 10;
  } while (x);
  if (neg) putchar('-');
  for (int i = (cnt); i >= (1); --i) putchar(ch[i]);
}
template <typename T>
void Writeln(T x) {
  Write(x);
  putchar('\n');
}
template <typename T>
void Writesp(T x) {
  Write(x);
  putchar(' ');
}
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
const int MAX = 55;
const int MAXS = 105;
int n, m;
pair<int, int> s;
char a[MAX][MAX];
char S[MAXS];
void Enter() {
  Read(n);
  Read(m);
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) {
      char ch;
      do {
        ch = getchar();
      } while (ch != '.' && ch != 'S' && ch != '#' && ch != 'E');
      if (ch == 'S') s = pair<int, int>(i, j);
      a[i][j] = ch;
    }
  scanf("%s", S + 1);
}
void Add(pair<int, int> &x, int y) {
  x.first += dx[y];
  x.second += dy[y];
}
void Solve() {
  int cnt = 0;
  for (int i0 = (0); i0 <= (3); ++i0)
    for (int i1 = (0); i1 <= (3); ++i1) {
      if (i1 == i0) continue;
      for (int i2 = (0); i2 <= (3); ++i2) {
        if (i2 == i1 || i2 == i0) continue;
        for (int i3 = (0); i3 <= (3); ++i3) {
          if (i3 == i2 || i3 == i1 || i3 == i0) continue;
          pair<int, int> u = s;
          bool check = 0;
          for (int k = (1); k <= (strlen(S + 1)); ++k) {
            if (S[k] == '0') Add(u, i0);
            if (S[k] == '1') Add(u, i1);
            if (S[k] == '2') Add(u, i2);
            if (S[k] == '3') Add(u, i3);
            if (u.first < 1 || u.first > n || u.second < 1 || u.second > m) {
              check = 0;
              break;
            }
            if (a[u.first][u.second] == '#') {
              check = 0;
              break;
            }
            if (a[u.first][u.second] == 'E') {
              check = 1;
              break;
            }
          }
          if (check) ++cnt;
        }
      }
    }
  Write(cnt);
}
int main(int argc, char const *argv[]) {
  Enter();
  Solve();
  return 0;
}
