#include<iostream>
#include<map>
#include<queue>
using namespace std;

typedef pair<string,int> P;

int main(){
  int h,w,d;
  string tmp,g;
  int dx[] = {0,1,0,-1}, dy[] = {-1,0,1,0};
  bool f;
  map<string,int> m;
  P p;

  while(cin >> h >> w, h||w){
    g = "";
    for(int i=0;i<h;i++){
      cin >> tmp;
      g += tmp;
    }

    m.clear();
    deque<P> q;
    q.push_back(P(g,1));

    f = false;
    while(!q.empty()){
      p = q.front(); q.pop_front();
      g = p.first; d = p.second;
      if(m[g])continue;
      m[g] = d;

      int y,x;
      for(int i=0;i<h;i++){
	for(int j=0;j<w;j++){
	  if(g[i*w+j] == '@'){
	    y = i; x = j; break;
	  }
	}
      }

      for(int i=0;i<4;i++){
	int sy = y+dy[i], sx = x+dx[i];
	if(g[sy*w+sx] == '#' || g[sy*w+sx] == 'w')continue;
	if(g[sy*w+sx] == 'E'){
	  cout << d << endl;
	  f = true; break;
	}
	if(g[sy*w+sx] == '.'){
	  tmp = g;
	  tmp[y*w+x] = '.';
	  tmp[sy*w+sx] = '@';
	  q.push_back(P(tmp,d+1));
	}
	if(g[sy*w+sx] == 'c'){
	  tmp = g;
	  tmp[sy*w+sx] = '.';
	  for(;;){
	    sy += dy[i]; sx += dx[i];
	    if(tmp[sy*w+sx] == '#' || tmp[sy*w+sx] == 'c'){
	      tmp[(sy-dy[i])*w+(sx-dx[i])] = 'c';
	      break;
	    }
	    if(tmp[sy*w+sx] == 'w'){
	      tmp[sy*w+sx] = '.';
	      break;
	    }
	  }
	  q.push_front(P(tmp,d));
	}
      }
      if(f)break;
    }
    if(!f)cout << -1 << endl;
  }
}