#include <bits/stdc++.h>
using namespace std;
string s[105];
int arr[] = {0, 1, 2, 3};
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  string mo;
  s[0] = s[n + 1] = "";
  for (int i = 0; i <= m; ++i) {
    s[0] = s[0] + "0";
  }
  s[n + 1] = s[0];
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    s[i] = "0" + s[i] + "0";
  }
  cin >> mo;
  int ans = 0;
  do {
    bool flag = 1;
    int stx, sty;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        if (s[i][j] == 'S') {
          stx = i;
          sty = j;
          flag = 0;
          break;
        }
      }
      if (!flag) break;
    }
    flag = 1;
    for (int i = 0; i < mo.size(); ++i) {
      if (arr[mo[i] - '0'] == 0) {
        --stx;
        if (s[stx][sty] == '0' || s[stx][sty] == '#') {
          flag = 0;
          break;
        }
      }
      if (arr[mo[i] - '0'] == 1) {
        ++stx;
        if (s[stx][sty] == '0' || s[stx][sty] == '#') {
          flag = 0;
          break;
        }
      }
      if (arr[mo[i] - '0'] == 2) {
        --sty;
        if (s[stx][sty] == '0' || s[stx][sty] == '#') {
          flag = 0;
          break;
        }
      }
      if (arr[mo[i] - '0'] == 3) {
        ++sty;
        if (s[stx][sty] == '0' || s[stx][sty] == '#') {
          flag = 0;
          break;
        }
      }
      if (s[stx][sty] == 'E') {
        ++ans;
        break;
      }
    }
  } while (next_permutation(arr, arr + 4));
  cout << ans << endl;
  return 0;
}
