#include <bits/stdc++.h>
using namespace std;
int binarylow(vector<long long> &a, long long low, long long high,
              long long k) {
  long long mid = (low + high) / 2;
  if (low > high)
    return high;
  else if (a[mid] == k)
    return binarylow(a, low, mid - 1, k);
  else if (a[mid] < k)
    return binarylow(a, mid + 1, high, k);
  else if (a[mid] > k)
    return binarylow(a, low, mid - 1, k);
}
int binary(vector<long long> &a, long long low, long long high, long long k) {
  long long mid = (low + high) / 2;
  if (low > high)
    return -1;
  else if (a[mid] == k)
    return mid;
  else if (a[mid] < k)
    return binary(a, mid + 1, high, k);
  else if (a[mid] > k)
    return binary(a, low, mid - 1, k);
}
int binaryhigh(vector<long long> &a, long long low, long long high,
               long long k) {
  long long mid = (low + high) / 2;
  if (low > high)
    return low;
  else if (a[mid] == k)
    return binaryhigh(a, mid + 1, high, k);
  else if (a[mid] < k)
    return binaryhigh(a, mid + 1, high, k);
  else if (a[mid] > k)
    return binaryhigh(a, low, mid - 1, k);
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long power(long long x, long long n) {
  long long res = 1;
  if (n == 0)
    return 1;
  else if (n == 1)
    return x;
  else {
    while (n > 0) {
      if (n % 2 == 1) {
        res = ((res % 1000000007) * (x % 1000000007)) % 1000000007;
        n--;
      } else {
        x = ((x % 1000000007) * (x % 1000000007)) % 1000000007;
        n = (n) / 2;
      }
    }
    return res % 1000000007;
  }
}
long long fact(long long x) {
  long long ans = 1, num = 2;
  while (num <= x) {
    ans = ((ans % 1000000007) * (num % 1000000007)) % 1000000007;
    num++;
  }
  return (ans % 1000000007);
}
int main() {
  long long t;
  t = 1;
  while (t--) {
    long long rows, cols, i, j;
    cin >> rows >> cols;
    vector<string> s;
    for (i = 0; i < rows; i++) {
      string s1;
      cin >> s1;
      s.push_back(s1);
    }
    string dir;
    cin >> dir;
    long long startr, startc, f = 0;
    for (i = 0; i < rows; i++) {
      for (j = 0; j < cols; j++) {
        if (s[i][j] == 'S') {
          f = 1;
          startr = i;
          startc = j;
          break;
        }
      }
      if (f) break;
    }
    long long l, r, u, d, ans = 0;
    map<long long, char> m;
    ans = 0;
    for (l = 0; l < 4; l++) {
      for (r = 0; r < 4; r++) {
        if (r != l) {
          for (u = 0; u < 4; u++) {
            if ((u != l) && (u != r)) {
              for (d = 0; d < 4; d++) {
                if ((d != l) && (d != r) && (d != u)) {
                  m[l] = 'L';
                  m[r] = 'R';
                  m[d] = 'D';
                  m[u] = 'U';
                  long long ro = startr, c = startc;
                  f = 0;
                  for (i = 0; i < dir.length(); i++) {
                    if (m[dir[i] - '0'] == 'L')
                      c--;
                    else if (m[dir[i] - '0'] == 'R')
                      c++;
                    else if (m[dir[i] - '0'] == 'D')
                      ro++;
                    else
                      ro--;
                    if ((ro < 0) || (ro >= rows)) {
                      f = 1;
                      break;
                    }
                    if ((c < 0) || (c >= cols)) {
                      f = 1;
                      break;
                    }
                    if (s[ro][c] == '#') {
                      f = 1;
                      break;
                    }
                    if (s[ro][c] == 'E') break;
                  }
                  if ((!f) && (s[ro][c] == 'E')) ans++;
                }
              }
            }
          }
        }
      }
    }
    cout << ans;
  }
}
