#include <bits/stdc++.h>
using namespace std;
char dir[4] = {'D', 'L', 'R', 'U'};
char a[50][50];
int main() {
  int i, j, m, n, si, sj, ei, ej, ans, k, len, d;
  char ch;
  string s;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'S') {
        si = i;
        sj = j;
      }
      if (a[i][j] == 'E') {
        ei = i;
        ej = j;
      }
    }
  }
  cin >> s;
  len = s.length();
  ans = 0;
  do {
    i = si;
    j = sj;
    for (k = 0; k < len; k++) {
      if (i < 0 || i >= n || j < 0 || j >= m) break;
      if (a[i][j] == '#') break;
      if (i == ei && j == ej) break;
      d = s[k] - '0';
      ch = dir[d];
      if (ch == 'U') {
        i--;
      } else if (ch == 'D')
        i++;
      else if (ch == 'L')
        j--;
      else
        j++;
    }
    if (i == ei && j == ej) {
      ans++;
    }
  } while (next_permutation(dir, dir + 4));
  cout << ans << endl;
}
