#include <bits/stdc++.h>
using namespace std;
pair<int, int> dir[4];
int ans = 0;
int n, m;
char maz[55][55];
char op[105];
void bfs() {
  int x, y;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (maz[i][j] == 'S') {
        x = i, y = j;
      }
    }
  }
  for (int i = 0; op[i]; ++i) {
    int t = op[i] - '0';
    x += dir[t].first;
    y += dir[t].second;
    if (x < 1 || y < 1 || x > n || y > m || maz[x][y] == '#') return;
    if (maz[x][y] == 'E') {
      ans++;
      return;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    scanf("%s", maz[i] + 1);
  }
  scanf("%s", op);
  dir[0] = pair<int, int>(0, 1);
  dir[1] = pair<int, int>(0, -1);
  dir[2] = pair<int, int>(1, 0);
  dir[3] = pair<int, int>(-1, 0);
  sort(dir, dir + 4);
  do {
    bfs();
  } while (next_permutation(dir, dir + 4));
  cout << ans << endl;
}
