#include <bits/stdc++.h>
using namespace std;
string s[1000], a;
int n, m, ax, ay, bx, by, ans = 0;
bool check(string s1) {
  int ax1 = ax, ay1 = ay;
  for (int i = 0; i < s1.size(); i++) {
    if (s1[i] == '0')
      ax1--;
    else if (s1[i] == '1')
      ay1++;
    else if (s1[i] == '2')
      ax1++;
    else if (s1[i] == '3')
      ay1--;
    if (ax1 < 0 || ax1 > n - 1 || ay1 < 0 || ay1 > m - 1) return 0;
    if (s[ax1][ay1] == '#') return 0;
    if (ax1 == bx && ay1 == by) return 1;
  }
  return 0;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'S') {
        ax = i;
        ay = j;
      }
      if (s[i][j] == 'E') {
        bx = i;
        by = j;
      }
    }
  cin >> a;
  int asize = a.size();
  for (int i0 = '0'; i0 < '4'; i0++)
    for (int i1 = '0'; i1 < '4'; i1++)
      for (int i2 = '0'; i2 < '4'; i2++)
        for (int i3 = '0'; i3 < '4'; i3++) {
          if (i0 != i1 && i0 != i2 && i0 != i3 && i1 != i2 && i1 != i3 &&
              i2 != i3) {
            string b = "";
            for (int j = 0; j < asize; j++)
              if (a[j] == '0')
                b += i0;
              else if (a[j] == '1')
                b += i1;
              else if (a[j] == '2')
                b += i2;
              else if (a[j] == '3')
                b += i3;
            if (check(b)) ans++;
          }
        }
  cout << ans;
  return 0;
}
