#include <bits/stdc++.h>
using namespace std;
const int qx[4] = {-1, 1, 0, 0}, qy[4] = {0, 0, -1, 1};
int n, m, a[55][55], x, y, go[150], i[5], bu, ans;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      char ch = getchar();
      while (ch != '.' && ch != '#' && ch != 'S' && ch != 'E') ch = getchar();
      a[i][j] = ch;
      if (ch == 'S') x = i, y = j, a[i][j] = '.';
    }
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') go[++bu] = ch - '0', ch = getchar();
  for (i[1] = 0; i[1] <= 3; i[1]++)
    for (i[2] = 0; i[2] <= 3; i[2]++)
      if (i[2] != i[1])
        for (i[3] = 0; i[3] <= 3; i[3]++)
          if (i[3] != i[2] && i[3] != i[1])
            for (i[4] = 0; i[4] <= 3; i[4]++)
              if (i[4] != i[3] && i[4] != i[2] && i[4] != i[1]) {
                int X = x, Y = y;
                for (int k = 1; k <= bu; k++)
                  if (a[X + qx[i[go[k] + 1]]][Y + qy[i[go[k] + 1]]] == '.')
                    X += qx[i[go[k] + 1]], Y += qy[i[go[k] + 1]];
                  else if (a[X + qx[i[go[k] + 1]]][Y + qy[i[go[k] + 1]]] ==
                           'E') {
                    ans++;
                    break;
                  } else if (X + qx[i[go[k] + 1]] < 1 ||
                             X + qx[i[go[k] + 1]] > n ||
                             Y + qy[i[go[k] + 1]] < 1 ||
                             Y + qy[i[go[k] + 1]] > m ||
                             a[X + qx[i[go[k] + 1]]][Y + qy[i[go[k] + 1]]] ==
                                 '#')
                    break;
              }
  cout << ans;
}
