#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}
int sum(int x, int y) {
  add(x, y);
  return x;
}
int diff(int &x, int y) {
  if ((x -= y) < 0) {
    x += mod;
  }
}
int sub(int x, int y) {
  diff(x, y);
  return x;
}
int mult(int x, int y) { return (long long)x * y % mod; }
int power(int x, long long p) {
  int res = 1;
  while (p) {
    if (p & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
    p >>= 1;
  }
  return res;
}
int inv(int x) { return power(x, mod - 2); }
const int inf = (int)1.01e9;
const long double eps = 1e-8;
const long double pi = acos(-1.0L);
const int maxn = (int)2e5 + 100;
char desk[100][100];
string s;
bool check(vector<int> &dir, int i, int sx, int sy, int fx, int fy) {
  if (sx == fx && sy == fy) {
    return true;
  }
  if (desk[sx][sy] == '#') {
    return false;
  }
  if (i == s.size()) {
    return false;
  }
  if (dir[s[i] - '0'] == 0) {
    return check(dir, i + 1, sx, sy - 1, fx, fy);
  } else if (dir[s[i] - '0'] == 1) {
    return check(dir, i + 1, sx - 1, sy, fx, fy);
  } else if (dir[s[i] - '0'] == 2) {
    return check(dir, i + 1, sx, sy + 1, fx, fy);
  } else {
    return check(dir, i + 1, sx + 1, sy, fx, fy);
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 60; ++i) {
    for (int j = 0; j < 60; ++j) {
      desk[i][j] = '#';
    }
  }
  int sx, sy, fx, fy;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> desk[i][j];
      if (desk[i][j] == 'S') {
        sx = i, sy = j;
        desk[i][j] = '.';
      }
      if (desk[i][j] == 'E') {
        fx = i, fy = j;
        desk[i][j] = '.';
      }
    }
  }
  cin >> s;
  vector<int> dir = {0, 1, 2, 3};
  int ans = check(dir, 0, sx, sy, fx, fy);
  while (next_permutation(dir.begin(), dir.end())) {
    ans += check(dir, 0, sx, sy, fx, fy);
  }
  cout << ans;
  cout << endl;
}
void precalc() {}
void clear() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cout.precision(5);
  srand((unsigned int)time(0));
  cout << fixed;
  precalc();
  int task_count = 1;
  for (int i = 1; i <= task_count; ++i) {
    solve();
    clear();
  }
  return 0;
}
