#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[] = {-1, 1, 0, 0, 1, -1, 1, -1};
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
char arr[100][100];
int n, m;
string s;
bool valid(int i, int j) { return i >= 0 && j >= 0 && i < n && j < m; }
void change_dir(int &i, int &j, char dir) {
  if (dir == 'L')
    j--;
  else if (dir == 'R')
    j++;
  else if (dir == 'U')
    i--;
  else if (dir == 'D')
    i++;
}
int main() {
  fast();
  string dir = "LRUD";
  sort(dir.begin(), dir.end());
  int X, Y;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == 'S') {
        X = i;
        Y = j;
      }
    }
  }
  cin >> s;
  int ans = 0;
  do {
    bool ok = true;
    int x = X;
    int y = Y;
    for (int i = 0; i < s.size(); i++) {
      change_dir(x, y, dir[s[i] - '0']);
      if (!valid(x, y)) {
        break;
      } else if (arr[x][y] == '#') {
        break;
      } else if (arr[x][y] == 'E') {
        ans++;
        break;
      }
    }
  } while (next_permutation(dir.begin(), dir.end()));
  cout << ans;
}
