#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0, xs, ys, xe, ye;
  char q[105][105];
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> q[i][j];
      if (q[i][j] == 'S') {
        xs = i;
        ys = j;
      }
      if (q[i][j] == 'E') {
        xe = i;
        ye = j;
      }
    }
  }
  string line;
  cin >> line;
  int x, y;
  for (int w = 0; w <= 3; ++w) {
    for (int l = 0; l <= 3; ++l) {
      for (int s = 0; s <= 3; ++s) {
        for (int r = 0; r <= 3; ++r) {
          if (w == l || w == s || w == r) {
            continue;
          }
          if (l == s || l == r) {
            continue;
          }
          if (s == r) {
            continue;
          }
          x = xs;
          y = ys;
          for (int i = 0; i < line.size(); ++i) {
            int p = line[i] - '0';
            if (p == w) {
              x++;
              if (x >= n) {
                break;
              }
            }
            if (p == l) {
              y--;
              if (y < 0) {
                break;
              }
            }
            if (p == s) {
              x--;
              if (x < 0) {
                break;
              }
            }
            if (p == r) {
              y++;
              if (y >= m) {
                break;
              }
            }
            if (x == xe && y == ye) {
              break;
            }
            if (q[x][y] == '#') {
              break;
            }
          }
          if (x == xe && y == ye) {
            ans++;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
