#include <bits/stdc++.h>
using namespace std;
bool go(char** a, int n, int m, int startR, int startC, string s,
        string arr[4]) {
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == '0') {
      if (arr[0] == "up")
        --startR;
      else if (arr[0] == "down")
        ++startR;
      else if (arr[0] == "right")
        ++startC;
      else
        --startC;
    } else if (s[i] == '1') {
      if (arr[1] == "up")
        --startR;
      else if (arr[1] == "down")
        ++startR;
      else if (arr[1] == "right")
        ++startC;
      else
        --startC;
    } else if (s[i] == '2') {
      if (arr[2] == "up")
        --startR;
      else if (arr[2] == "down")
        ++startR;
      else if (arr[2] == "right")
        ++startC;
      else
        --startC;
    } else {
      if (arr[3] == "up")
        --startR;
      else if (arr[3] == "down")
        ++startR;
      else if (arr[3] == "right")
        ++startC;
      else
        --startC;
    }
    if (startR >= 0 && startR < n && startC >= 0 && startC < m) {
      if (a[startR][startC] == '#')
        return 0;
      else if (a[startR][startC] == 'E')
        return 1;
    } else
      return 0;
  }
  return 0;
}
int main() {
  int n, m, startR, startC, res = 0;
  cin >> n >> m;
  char** a = new char*[n];
  for (int i = 0; i < n; ++i) a[i] = new char[m];
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) {
    bool found = 0;
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == 'S') {
        startR = i;
        startC = j;
        found = 1;
      }
    }
    if (found) break;
  }
  string s;
  cin >> s;
  string arr[4] = {"up", "down", "right", "left"};
  sort(arr, arr + 4);
  do {
    res += go(a, n, m, startR, startC, s, arr);
  } while (next_permutation(arr, arr + 4));
  cout << res;
  return 0;
}
