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

int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};

char lab[10][10];
struct NODE{
	int x,y;
	int px[3],py[3];
	int dead;
	int cdead;
	NODE(){
		x = y = 0;
		px[0] = px[1] = px[2] = 0;
		py[0] = py[1] = py[2] = 0;
		dead = 0;
		cdead = 0;
	}
};
bool operator < (const NODE &a,const NODE &b){
	if( a.x != b.x ) return a.x < b.x;
	if( a.y != b.y ) return a.y < b.y;
	if( a.px[0] != b.px[0] ) return a.px[0] < b.px[0];
	if( a.px[1] != b.px[1] ) return a.px[1] < b.px[1];
	if( a.px[2] != b.px[2] ) return a.px[2] < b.px[2];
	if( a.py[0] != b.py[0] ) return a.py[0] < b.py[0];
	if( a.py[1] != b.py[1] ) return a.py[1] < b.py[1];
	if( a.py[2] != b.py[2] ) return a.py[2] < b.py[2];
	if( a.dead != b.dead ) return a.dead < b.dead;
	if( a.cdead != b.cdead ) return a.cdead < b.cdead;
	return false;
}

int main(){
	int H,W;
	while( cin >> H >> W && H ){
		int wx[3],wy[3];
		map<NODE,int> done;
		NODE fst; int cc = 0 , ww = 0;
		for(int i = 0 ; i < H ; i++){
			for(int j = 0 ; j < W ; j++){
				cin >> lab[i][j];
				if( lab[i][j] == '@' ) fst.x = j , fst.y = i;
				if( lab[i][j] == 'c' ){
					fst.px[cc] = j;
					fst.py[cc++] = i;
				}
				if( lab[i][j] == 'w' ){
					wx[ww] = j;
					wy[ww++] = i;
				}
			}
		}
		priority_queue< pair<int,NODE> , vector< pair<int,NODE> > , greater<  pair<int,NODE> >  > Q;
		done[fst] = 0;
		Q.push(make_pair(0,fst));
		
		while( Q.size() ){
			NODE q = Q.top().second;
			int cost = Q.top().first;
			Q.pop();
			if( done[q] != cost ) continue;
			if( lab[q.y][q.x] == 'E' ){
				cout << cost << endl;
				goto exit;
			}
			for(int d = 0 ; d < 4 ; d++){
				int tx = q.x + dx[d];
				int ty = q.y + dy[d];
				if( lab[ty][tx] == '#' ) continue;
				int fail = 0;
				for(int i = 0 ; i < ww ; i++){
					if( !(q.dead >> i & 1) && tx == wx[i] && ty == wy[i] ) fail = 1;
				}
				if(fail) continue;
				
				NODE next = q;
				for(int i = 0 ; i < cc ; i++){
					if( !(q.cdead >> i & 1) && tx == q.px[i] && ty == q.py[i] ){
						int mx = tx;
						int my = ty;
						while( lab[my+dy[d]][mx+dx[d]] != '#' ){
							int br = 0;
							for(int j = 0 ; j < cc ; j++){
								if( !(q.cdead >> j & 1) && mx+dx[d] == q.px[j] && my+dy[d] == q.py[j] )
									br = 1;
							}
							if(br) break;
							mx += dx[d];
							my += dy[d];
							for(int j = 0 ; j < ww ; j++){
								if( !(q.dead >> j & 1) && mx == wx[j] && my == wy[j] ){
									br = 1;
									next.cdead |= (1<<i);
									next.dead |= (1<<j);
									mx = 0;
									my = 0;
									break;
								}
							}
							if(br) break;
						}
						next.px[i] = mx;
						next.py[i] = my;
						tx = q.x;
						ty = q.y;
					}
				}
				int diff = q.y != ty || q.x != tx;
				next.x = tx , next.y = ty;
				if( !done.count(next) || done[next] > cost+diff ){
					Q.push(make_pair(diff+cost,next));
					done[next] = cost+diff;
				}
			}
		}
		cout << -1 << endl;
		exit:;
		
	}
}