#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long inf = 4e18;
const long long N = 1e5;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  char a[n][m];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) cin >> a[i][j];
  }
  long long I, J;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (a[i][j] == 'S') I = i, J = j;
    }
  }
  string s;
  cin >> s;
  char dir[4] = {'d', 'l', 'r', 'u'};
  long long o = 0;
  do {
    bool boob = 0;
    long long i = I, j = J;
    for (long long k = 0; k < s.length(); k++) {
      char p = dir[s[k] - '0'];
      if (p == 'u')
        i--;
      else if (p == 'l')
        j--;
      else if (p == 'r')
        j++;
      else
        i++;
      if (i < 0 || j < 0 || i >= n || j >= m) break;
      if (a[i][j] == '#') break;
      if (a[i][j] == 'E') {
        boob = 1;
        break;
      }
    }
    if (boob) o++;
  } while (next_permutation(dir, dir + 4));
  cout << o << endl;
}
