#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, char> > vecc[24];
int main() {
  vecc[0].push_back(make_pair(0, 'L'));
  vecc[0].push_back(make_pair(1, 'R'));
  vecc[0].push_back(make_pair(2, 'U'));
  vecc[0].push_back(make_pair(3, 'D'));
  vecc[1].push_back(make_pair(0, 'L'));
  vecc[1].push_back(make_pair(1, 'R'));
  vecc[1].push_back(make_pair(2, 'D'));
  vecc[1].push_back(make_pair(3, 'U'));
  vecc[2].push_back(make_pair(0, 'L'));
  vecc[2].push_back(make_pair(1, 'D'));
  vecc[2].push_back(make_pair(2, 'U'));
  vecc[2].push_back(make_pair(3, 'R'));
  vecc[3].push_back(make_pair(0, 'L'));
  vecc[3].push_back(make_pair(1, 'D'));
  vecc[3].push_back(make_pair(2, 'R'));
  vecc[3].push_back(make_pair(3, 'U'));
  vecc[4].push_back(make_pair(0, 'L'));
  vecc[4].push_back(make_pair(1, 'U'));
  vecc[4].push_back(make_pair(2, 'R'));
  vecc[4].push_back(make_pair(3, 'D'));
  vecc[5].push_back(make_pair(0, 'L'));
  vecc[5].push_back(make_pair(1, 'U'));
  vecc[5].push_back(make_pair(2, 'D'));
  vecc[5].push_back(make_pair(3, 'R'));
  vecc[6].push_back(make_pair(0, 'R'));
  vecc[6].push_back(make_pair(1, 'L'));
  vecc[6].push_back(make_pair(2, 'U'));
  vecc[6].push_back(make_pair(3, 'D'));
  vecc[7].push_back(make_pair(0, 'R'));
  vecc[7].push_back(make_pair(1, 'L'));
  vecc[7].push_back(make_pair(2, 'D'));
  vecc[7].push_back(make_pair(3, 'U'));
  vecc[8].push_back(make_pair(0, 'R'));
  vecc[8].push_back(make_pair(1, 'D'));
  vecc[8].push_back(make_pair(2, 'U'));
  vecc[8].push_back(make_pair(3, 'L'));
  vecc[9].push_back(make_pair(0, 'R'));
  vecc[9].push_back(make_pair(1, 'D'));
  vecc[9].push_back(make_pair(2, 'L'));
  vecc[9].push_back(make_pair(3, 'U'));
  vecc[10].push_back(make_pair(0, 'R'));
  vecc[10].push_back(make_pair(1, 'U'));
  vecc[10].push_back(make_pair(2, 'L'));
  vecc[10].push_back(make_pair(3, 'D'));
  vecc[11].push_back(make_pair(0, 'R'));
  vecc[11].push_back(make_pair(1, 'U'));
  vecc[11].push_back(make_pair(2, 'D'));
  vecc[11].push_back(make_pair(3, 'L'));
  vecc[12].push_back(make_pair(0, 'U'));
  vecc[12].push_back(make_pair(1, 'R'));
  vecc[12].push_back(make_pair(2, 'L'));
  vecc[12].push_back(make_pair(3, 'D'));
  vecc[13].push_back(make_pair(0, 'U'));
  vecc[13].push_back(make_pair(1, 'R'));
  vecc[13].push_back(make_pair(2, 'D'));
  vecc[13].push_back(make_pair(3, 'L'));
  vecc[14].push_back(make_pair(0, 'U'));
  vecc[14].push_back(make_pair(1, 'D'));
  vecc[14].push_back(make_pair(2, 'L'));
  vecc[14].push_back(make_pair(3, 'R'));
  vecc[15].push_back(make_pair(0, 'U'));
  vecc[15].push_back(make_pair(1, 'D'));
  vecc[15].push_back(make_pair(2, 'R'));
  vecc[15].push_back(make_pair(3, 'L'));
  vecc[16].push_back(make_pair(0, 'U'));
  vecc[16].push_back(make_pair(1, 'L'));
  vecc[16].push_back(make_pair(2, 'R'));
  vecc[16].push_back(make_pair(3, 'D'));
  vecc[17].push_back(make_pair(0, 'U'));
  vecc[17].push_back(make_pair(1, 'L'));
  vecc[17].push_back(make_pair(2, 'D'));
  vecc[17].push_back(make_pair(3, 'R'));
  vecc[18].push_back(make_pair(0, 'D'));
  vecc[18].push_back(make_pair(1, 'R'));
  vecc[18].push_back(make_pair(2, 'U'));
  vecc[18].push_back(make_pair(3, 'L'));
  vecc[19].push_back(make_pair(0, 'D'));
  vecc[19].push_back(make_pair(1, 'R'));
  vecc[19].push_back(make_pair(2, 'L'));
  vecc[19].push_back(make_pair(3, 'U'));
  vecc[20].push_back(make_pair(0, 'D'));
  vecc[20].push_back(make_pair(1, 'L'));
  vecc[20].push_back(make_pair(2, 'U'));
  vecc[20].push_back(make_pair(3, 'R'));
  vecc[21].push_back(make_pair(0, 'D'));
  vecc[21].push_back(make_pair(1, 'L'));
  vecc[21].push_back(make_pair(2, 'R'));
  vecc[21].push_back(make_pair(3, 'U'));
  vecc[22].push_back(make_pair(0, 'D'));
  vecc[22].push_back(make_pair(1, 'U'));
  vecc[22].push_back(make_pair(2, 'R'));
  vecc[22].push_back(make_pair(3, 'L'));
  vecc[23].push_back(make_pair(0, 'D'));
  vecc[23].push_back(make_pair(1, 'U'));
  vecc[23].push_back(make_pair(2, 'L'));
  vecc[23].push_back(make_pair(3, 'R'));
  long long n, m;
  cin >> n >> m;
  char cc[n][m];
  long long ssx, ssy;
  long long ex, ey;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      cin >> cc[i][j];
      if (cc[i][j] == 'S') {
        ssx = i;
        ssy = j;
      }
      if (cc[i][j] == 'E') {
        ex = i;
        ey = j;
      }
    }
  string ss;
  cin >> ss;
  long long anss = 0;
  for (long long i = 0; i < 24; i++) {
    long long sx = ssx;
    long long sy = ssy;
    long long flag = 0;
    for (long long j = 0; j < ss.length(); j++) {
      char ccd = ss[j];
      if (vecc[i][(long long)(ccd - 48)].second == 'U') {
        sx += 1;
      } else if (vecc[i][(long long)(ccd - 48)].second == 'D') {
        sx -= 1;
      } else if (vecc[i][(long long)(ccd - 48)].second == 'L') {
        sy -= 1;
      } else if (vecc[i][(long long)(ccd - 48)].second == 'R') {
        sy += 1;
      }
      if (sx < 0 or sx >= n or sy < 0 or sy >= m) {
        flag = 1;
        break;
      } else if (cc[sx][sy] == '#') {
        flag = 1;
        break;
      } else if (sx == ex and sy == ey) {
        flag = 2;
        break;
      }
    }
    if (flag == 2) anss++;
  }
  cout << anss << endl;
  return 0;
}
