#include <bits/stdc++.h>
using namespace std;
int main() {
  int l1, r, u, d;
  string s;
  int n, m, a, b, a1, b1;
  cin >> n >> m;
  char arr[100][100];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == 'S') {
        a1 = i;
        b1 = j;
      }
    }
  cin >> s;
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    l1 = i;
    for (int j = 0; j < 4; j++) {
      if (i == j) continue;
      r = j;
      for (int k = 0; k < 4; k++) {
        if (k == i || k == j) continue;
        u = k;
        for (int l = 0; l < 4; l++) {
          if (l == i || l == j || l == k) continue;
          d = l;
          a = a1;
          b = b1;
          for (int q = 0; q < s.length(); q++) {
            if (s[q] - '0' == l1)
              b--;
            else if (s[q] - '0' == r)
              b++;
            else if (s[q] - '0' == u)
              a--;
            else
              a++;
            if (a < 0 || b < 0 || a >= n || b >= m) break;
            if (arr[a][b] == 'E') {
              ans++;
              break;
            }
            if (arr[a][b] == '#') break;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
