#include <bits/stdc++.h>
using namespace std;
const long long Long_max = numeric_limits<long long>::max();
const int Int_max = numeric_limits<int>::max();
void File_input(string pathIn) { freopen(pathIn.c_str(), "r", stdin); }
void File_output(string pathOut) { freopen(pathOut.c_str(), "w", stdout); }
int msg() {
  srand(time(0));
  vector<string> st = {"Wish everyone high ratings!", "Good luck!", "Have fun!",
                       "Please, read all the problems!", "Go Go fight!"};
  cerr << st[rand() % (int)st.size()];
  return 0;
}
void FastInputOutput() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int n, m;
const int N = 70;
char a[N][N];
bool vaild(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
int dx[] = {0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0};
string dir = "0123";
int main() {
  int sx, sy;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'S') sx = i, sy = j;
    }
  }
  string str;
  cin >> str;
  unordered_map<char, pair<int, int> > p;
  int cnt = 0;
  do {
    p.clear();
    for (int i = 0; i < 4; i++) {
      p[dir[i]] = {dx[i], dy[i]};
    }
    int x = sx, y = sy;
    bool xm = 1, c = 0;
    for (auto i : str) {
      x = x + p[i].first;
      y = y + p[i].second;
      if (vaild(x, y)) {
        if (a[x][y] == '#') {
          xm = 0;
          break;
        }
        if (a[x][y] == 'E') {
          c = 1;
          break;
        }
      } else {
        xm = 0;
        break;
      }
    }
    cnt += xm && c;
  } while (next_permutation(dir.begin(), dir.end()));
  cout << cnt;
  return 0;
}
