#include <bits/stdc++.h>
using namespace std;
const long long N = 2000005;
bool col2(pair<long long, long long> p1, pair<long long, long long> p2) {
  if (p1.second == p2.second) return p1.first > p2.first;
  return p1.second > p2.second;
}
struct comp {
  bool operator()(long long const &x, long long const &y) { return x > y; }
};
int main() {
  long long n, m;
  cin >> n >> m;
  vector<string> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  string s;
  cin >> s;
  long long x = s.length();
  long long ans = 0;
  char arr[4];
  arr[0] = 'D';
  arr[1] = 'L';
  arr[2] = 'R';
  arr[3] = 'U';
  long long a = -1, b = -1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (v[i][j] == 'S') {
        a = i;
        b = j;
        break;
      }
    }
  }
  long long q1 = 0, q2 = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (v[i][j] == 'E') {
        q1 = i;
        q2 = j;
      }
    }
  }
  do {
    long long a1 = a;
    long long b1 = b;
    long long flag = 1;
    for (long long i = 0; i < x; i++) {
      long long y = s[i] - '0';
      if (arr[y] == 'U') a1--;
      if (arr[y] == 'D') a1++;
      if (arr[y] == 'R') b1++;
      if (arr[y] == 'L') b1--;
      if (a1 >= 0 && b1 >= 0 && a1 < n && b1 < m) {
        if (v[a1][b1] == '#') {
          flag = 0;
          break;
        } else {
          if (v[a1][b1] == 'E') break;
        }
      } else {
        flag = 0;
        break;
      }
    }
    if (flag) {
      if (a1 == q1 && b1 == q2) ans++;
    }
  } while (next_permutation(arr, arr + 4));
  cout << ans << endl;
}
