#include <bits/stdc++.h>
const long long M = 1e9 + 7;
const double pi = 3.14159265358979323846;
using namespace std;
vector<long long> adj[100005];
long long vis[100005] = {0};
long long fact(long long x) {
  if (x == 1 || x == 0)
    return 1;
  else
    return ((x % M) * (fact(x - 1) % M)) % M;
}
long long factorial(long long n) {
  const long long M = 1000000007;
  long long f = 1;
  for (long long i = 1; i <= n; i++) f = (f * i) % M;
  return f;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    long long n, M;
    cin >> n >> M;
    char arr[n][M];
    long long i1 = -1, i2 = -1;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < M; j++) {
        cin >> arr[i][j];
        if (arr[i][j] == 'S') {
          i1 = i;
          i2 = j;
        }
      }
    }
    string s;
    cin >> s;
    string temp = "DLRU";
    long long cnt = 0;
    do {
      long long flag = 0;
      long long a = i1, b = i2;
      for (long long j = 0; j < s.size(); j++) {
        long long p = (long long)s[j] - 48;
        char ch = temp[p];
        if (arr[a][b] == 'E') {
          flag = 1;
          break;
        }
        if (ch == 'U' && a - 1 >= 0 && arr[a - 1][b] != '#')
          a -= 1;
        else if (ch == 'D' && a + 1 < n && arr[a + 1][b] != '#')
          a += 1;
        else if (ch == 'L' && b - 1 >= 0 && arr[a][b - 1] != '#')
          b -= 1;
        else if (ch == 'R' && b + 1 < M && arr[a][b + 1] != '#')
          b += 1;
        else
          break;
      }
      if (flag == 1) {
        cnt++;
      }
      if (flag == 0 && arr[a][b] == 'E') cnt++;
    } while (next_permutation(temp.begin(), temp.end()));
    cout << (cnt) << "\n";
  }
  return 0;
}
