#include<iostream>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;

#define MAX 16
#define WALL '#'
#define EXIT 'E'
#define CONT 'c'
#define PANEL 'w'
#define CELL '.'
#define NAKAMURA '@'

#define fr first
#define sc second

#define WC 4
#define INF (1<<28)

const int di[] = {-1,0,1,0};
const int dj[] = {0,1,0,-1};

typedef pair<int,int> pi;

struct State{
  pi p;
  bool wvis[WC];
  pi cons[WC];

  State():p(pi(-1,-1)){
    fill(wvis,wvis+WC,false);fill(cons,cons+WC,pi(-1,-1));
  }
  State(pi p, int st):p(p){}

  bool checkpos( const pi &n, int wid )const{
    for(int i = 0; i < WC; ++i){
      if( n.fr == cons[i].fr && n.sc == cons[i].sc ) return false;
    }
    if( wid < 0 ) return true;
    return wvis[ wid ];
  }

  bool operator<(const State &t)const{
    if( p.fr != t.p.fr ) return p.fr < t.p.fr;
    if (p.sc != t.p.sc ) return p.sc < t.p.sc;
    for(int i = 0; i < WC; ++i){
      if( wvis[i] != t.wvis[i] ) return wvis[i] < t.wvis[i];
    }
    for(int i = 0; i < WC; ++i){
      if( cons[i].fr != t.cons[i].fr ) return cons[i].fr < t.cons[i].fr;
      if( cons[i].sc != t.cons[i].sc ) return cons[i].sc < t.cons[i].sc;
    }
    return false;
  }
};

int bfs(int H, int W, char M[][MAX], int wid[][MAX], State init){
  int ret = INF;
  queue<State> qs;
  qs.push(init);
  map<State,int> vis;
  vis[init]=0;
  while(!qs.empty()){
    State now = qs.front();
    qs.pop();

    if( M[now.p.fr][now.p.sc] == EXIT ){ ret=min(ret,vis[now]);continue; }

    if( vis[now] > ret ) continue;
    //cout << "SIZE : " <<  qs.size() << endl;
    // cout << now.p.fr << ' ' << now.p.sc << " STEP : " << vis[now] << endl;
    
    // move
    for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
      pi next( now.p.fr+di[k], now.p.sc+dj[k] );
      if( M[next.fr][next.sc] == WALL )continue;
      if( !now.checkpos( next, wid[next.fr][next.sc] ) ) continue;
      State Next = now;
      Next.p = next;
      
      if(vis.find(Next)==vis.end()){
	//cout << " MOVE TO : " << next.fr << ' ' << next.sc;
	vis[Next] = vis[now]+1;
	//cout << " NOW STEP? : " << vis[now] << " NEXT STEP? : " << vis[Next] << " TRUE STEP : " << vis[now]+1 << endl;
	qs.push(Next);
      }else if( vis[Next] > vis[now]+1 ){
	vis[Next] = vis[now]+1;
	qs.push(Next);
      }
    }

    // push container
    for(int i = 0; i < WC; ++i){
      if( now.cons[i].first > 0 && now.cons[i].second > 0 ){
	for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
	  pi invest( now.cons[i].fr+di[k], now.cons[i].sc+dj[k] );
	  if( invest.fr == now.p.fr && invest.sc == now.p.sc ){
	    int dir = (k+2)%(sizeof(di)/sizeof(*di));
	    invest = pi( now.cons[i].fr+di[dir], now.cons[i].sc+dj[dir] );
	    while( true ){
	      if( M[invest.fr][invest.sc] == WALL ){ invest.fr -= di[dir]; invest.sc -= dj[dir]; break; }
	      if( !now.checkpos( invest, wid[invest.fr][invest.sc] ) ){
		for(int i = 0; i < WC; ++i){
		  if( invest.fr == now.cons[i].fr && invest.sc == now.cons[i].sc ){
		    invest.fr -= di[dir]; invest.sc -= dj[dir];
		    break;
		  }
		}
		break;
	      }
	      invest.fr += di[dir]; invest.sc += dj[dir];
	    }
	    State Next = now;
	    Next.cons[i] = pi( invest.fr, invest.sc );
	    if( wid[ invest.fr ][ invest.sc ] >= 0 ){
	      Next.wvis[ wid[invest.fr][invest.sc] ] = true;
	      Next.cons[i] = pi(-1,-1);
	    }
	    if(vis.find(Next)==vis.end()){
	      vis[Next] = vis[now];
	      //cout << "CONTAINER MOVED : " << now.cons[i].fr << ' ' << now.cons[i].sc << " TO " << invest.fr << ' ' << invest.sc << endl;
	      qs.push(Next);
	    }else if( vis[Next] > vis[now] ){
	      vis[Next]=vis[now];
	      //cout << "CONTAINER MOVED : " << now.cons[i].fr << ' ' << now.cons[i].sc << " TO " << invest.fr << ' ' << invest.sc << endl;
	      qs.push(Next);
	    }
	    
	  }
	}
      }
    }
    // cout << " END " << endl;
  }
  if( ret >= INF ) return -1;
  else return ret;
}


int main()
{
  while(true){
    int H,W;
    int wnum = 0, cnum = 0;
    char M[MAX][MAX];
    int wid[MAX][MAX];
    State init;

    cin >> H >> W;
    if( H == 0 && W == 0 ) break;
    for(int i = 0; i<H;++i){
      for(int j=0;j<W;++j){
	cin >> M[i][j];
	wid[i][j] = -1;
	if(M[i][j] == PANEL){
	  wid[i][j] = wnum;
	  M[i][j] = CELL;
	  ++wnum;
	}else if (M[i][j] == CONT){
	  M[i][j] = CELL;
	  init.cons[ cnum++ ] = pi(i,j);
	}else if( M[i][j] == NAKAMURA ){
	  M[i][j] = CELL;
	  init.p = pi(i,j);
	}
      }
    }

    cout << bfs( H, W, M, wid, init ) << endl;
    //cout << " -------------------------------\nEND OF DATASET\n------------------------------------" << endl;
  }
  return 0;
}