void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int h, w; rd(h, w);
  auto c=new char[][](h);
  foreach(i; 0..h) c[i]=readln.chomp.to!(char[]);
  auto t=readln.chomp.to!(char[]);

  import std.typecons;
  alias P=Tuple!(int, "i", int, "j");
  P st, gl;
  foreach(i; 0..h)foreach(j; 0..w){
    if(c[i][j]=='S') st=P(i, j);
    if(c[i][j]=='E') gl=P(i, j);
  }
  auto dir=[[-1, 0], [0, 1], [1, 0], [0, -1]]; // LURD
  auto nums=[0, 1, 2, 3];
  int tot=0;
  do{
    auto cur=st;
    foreach(char ch; t){
      int x=ch-'0';
      auto d=dir[nums[x]];
      auto nex=P(cur.i+d[0], cur.j+d[1]);
      if(nex.i<0 || nex.i>=h || nex.j<0 || nex.j>=w) break;
      if(c[nex.i][nex.j]=='#') break;
      if(c[nex.i][nex.j]=='E'){tot++; break;}
      cur=nex;
    }
  }while(nextPermutation(nums));

  writeln(tot);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}