#include <bits/stdc++.h>
using namespace std;
string str[100], dir;
int ara[] = {0, 1, 2, 3};
int sx, sy, fx, fy;
int n, m;
bool func() {
  int i, j, k;
  int tx = sx, ty = sy;
  for (i = 0; i < dir.size(); ++i) {
    if (dir[i] - '0' == ara[0])
      ty--;
    else if (dir[i] - '0' == ara[1])
      ty++;
    else if (dir[i] - '0' == ara[2])
      tx--;
    else if (dir[i] - '0' == ara[3])
      tx++;
    if (tx < 0 || tx >= n || ty < 0 || ty >= m) return 0;
    if (str[tx][ty] == '#') return 0;
    if (tx == fx && ty == fy) return 1;
  }
}
int main() {
  int i, j, k;
  cin >> n >> m;
  for (i = 0; i < n; ++i) cin >> str[i];
  int cnt = 0;
  cin >> dir;
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      if (str[i][j] == 'S') sx = i, sy = j;
      if (str[i][j] == 'E') fx = i, fy = j;
    }
  }
  do {
    if (func()) cnt++;
  } while (next_permutation(ara, ara + 4));
  cout << cnt << endl;
}
