#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  char a[n][m];
  pair<int, int> st, en;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'S') {
        st = make_pair(i, j);
      }
      if (a[i][j] == 'E') {
        en = make_pair(i, j);
      }
    }
  }
  string in;
  cin >> in;
  vector<char> dir;
  dir.push_back('U');
  dir.push_back('L');
  dir.push_back('R');
  dir.push_back('D');
  sort(dir.begin(), dir.end());
  int ans = 0;
  do {
    pair<int, int> pos;
    pos = st;
    int flag = 0;
    for (int i = 0; i < in.length(); i++) {
      char no = dir[in[i] - '0'];
      switch (no) {
        case 'U':
          pos.first--;
          break;
        case 'L':
          pos.second--;
          break;
        case 'R':
          pos.second++;
          break;
        case 'D':
          pos.first++;
          break;
      }
      if (pos.first == en.first && pos.second == en.second) {
        flag = 1;
        ans++;
        break;
      }
      if (pos.first < 0 || pos.first >= n || pos.second < 0 ||
          pos.second >= m || a[pos.first][pos.second] == '#')
        break;
    }
    if (pos.first == en.first && pos.second == en.second && flag == 0) {
      ans++;
    }
  } while (next_permutation(dir.begin(), dir.end()));
  cout << ans;
  return 0;
}
