#include <bits/stdc++.h>
using namespace std;
struct node {
  int x;
  int y;
} S, E;
char maze[60][60];
string s;
int n, m;
int direction[4] = {0, 1, 2, 3};
void getMap() {
  for (int i = 0; i < n; i++) {
    cin >> maze[i];
    for (int j = 0; j < m; j++) {
      if (maze[i][j] == 'S') {
        S.x = i;
        S.y = j;
      }
      if (maze[i][j] == 'E') {
        E.x = i;
        E.y = j;
      }
    }
  }
}
int solve() {
  int x = S.x;
  int y = S.y;
  for (int i = 0; i < s.length(); i++) {
    int d = s[i] - '0';
    for (int j = 0; j < 4; j++) {
      if (d == direction[j]) {
        if (j == 0) y--;
        if (j == 1) y++;
        if (j == 2) x--;
        if (j == 3) x++;
      }
      if (x >= n || x < 0 || y >= m || y < 0)
        return 0;
      else if (maze[x][y] == '#')
        return 0;
      else if (maze[x][y] == 'E')
        return 1;
    }
  }
  return 0;
}
int main() {
  cin >> n >> m;
  getMap();
  cin >> s;
  int cnt = 0;
  do {
    cnt += solve();
  } while (next_permutation(direction, direction + 4));
  cout << cnt << endl;
  return 0;
}
