#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

int h,w;
char field[20][20];
const int INF=1000000000;
int gy,gx;
int sy,sx;

const int dy[]={-1,0,0,1};
const int dx[]={0,-1,1,0};
int d[20][20];
bool passed[20][20];

queue<pair<int,int> > *prv=new queue<pair<int,int> >();
queue<pair<int,int> > *nxt=new queue<pair<int,int> >();


// ツ個サツ催敖づ個湘ェツ渉環つゥツづァツ各ツ渉環づ鳴づ個催短ツ仰猟猟」
void bfs(int x,int y){
    //queue<int> *prvx=new queue<int>();
    //queue<int> *prvy=new queue<int>();
    //queue<int> *nxtx=new queue<int>();
    //queue<int> *nxty=new queue<int>();
    
    prv->push(make_pair(y,x));
    //prvx->push(x);
    //prvy->push(y);
    memset(passed,0,sizeof(passed));
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            d[i][j]=INF;
    int cnt=0;
    d[y][x]=0;
    passed[y][x]=true;
    while(prv->size()){
        while(prv->size()){
            //int cy=prvy->front();prvy->pop();
            //int cx=prvx->front();prvx->pop();
            int cy=prv->front().first;
            int cx=prv->front().second;
            prv->pop();
            for(int i = 0; i < 4; i++){
                int ny=cy+dy[i];
                int nx=cx+dx[i];
                if(ny>=0&&nx>=0&&ny<h&&nx<w&&!passed[ny][nx]&&field[ny][nx]=='.'){
                    passed[ny][nx]=true;
                    nxt->push(make_pair(ny,nx));
                    //nxty->push(ny);
                    //nxtx->push(nx);
                    d[ny][nx]=cnt+1;
                }
            }
        }
        cnt++;
        swap(prv,nxt);
        //swap(prvx,nxtx);
        //swap(prvy,nxty);
    }
    //delete prv;
    //delete nxt;

    //delete prvx;
    //delete nxtx;
    //delete prvy;
    //delete nxty;
}

// ツ残ツづづつ「ツづゥツコツδ督テツナツづ個暗環置
//vector<pair<int,int> > vpii;
pair<int,int> vpii[100];
int vpiiSize=0;
bool isExited[100];

int dfs(int cx,int cy){
    // ツ個サツ催敖づ個湘ェツ渉環つゥツづァツゴツーツδ仰づ鳴づ個催短ツ経ツ路ツづーツ仰づ淞づつィツつュ
    int minDist=INF;
    bfs(cx,cy);
    minDist=d[gy][gx];
    if(minDist<=1)
        return minDist;
    char tmpField[20][20];
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            tmpField[i][j]=field[i][j];
    int tmpD[20][20];
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            tmpD[i][j]=d[i][j];
    for(int i = 0; i < vpiiSize; i++){
        if(isExited[i])continue;
        for(int k = 0; k < 4; k++){
            int ny=vpii[i].first+dy[k];
            int nx=vpii[i].second+dx[k];
            if(ny>=0&&nx>=0&&ny<h&&nx<w&&field[ny][nx]=='.'&&tmpD[ny][nx]!=INF&&tmpD[ny][nx]<minDist){
                int nny=vpii[i].first-dy[k];
                int nnx=vpii[i].second-dx[k];
                bool isChange=false;
                // ツコツδ督テツナツつェツ１ツマツスツづづ                if(nny>=0&&nnx>=0&&nny<h&&nnx<w&&(field[nny][nnx]=='w'||field[nny][nnx]=='.')){
                    // Reið®©µÄAÄA
                    while(1){
                        // ReiðÁÅ³¹é
                        if(field[nny][nnx]=='w'){
                            field[nny+dy[k]][nnx+dx[k]]='.';
                            field[nny][nnx]='.';
                            isChange=true;
                            isExited[i]=true;
                            break;
                        }
                        else if(field[nny][nnx]=='.'){
                            field[nny+dy[k]][nnx+dx[k]]='.';
                            field[nny][nnx]='c';
                            nny-=dy[k];
                            nnx-=dx[k];
                            if(!(nny>=0&&nnx>=0&&nny<h&&nnx<w&&(field[nny][nnx]=='w'||field[nny][nnx]=='.')))
                                break;
                        }
                        // ÇÉÔÂ©Á½çI¹
                        else
                            break;
                    }
                    //                    if(field[gy][gx]!='c')
                    // ReiÌÊuªÏíÁ½±Æð«Ý
                    pair<int,int> prvInfo=vpii[i];
                    vpii[i].first=nny+dy[k];
                    vpii[i].second=nnx+dx[k];
                    int res=dfs(nx,ny)+tmpD[ny][nx];
                    if(minDist>res)
                        minDist=res;
                    vpii[i]=prvInfo;
                    //                    }
                    if(isChange)isExited[i]=false;
                    // zñð³ÉßµÄßé
                    for(int m = 0; m < h; m++)
                        for(int l = 0; l < w; l++)
                            field[m][l]=tmpField[m][l];
                }
            }
        }
    }
    return minDist;
}

int main(){
    while(scanf("%d %d\n",&h,&w)&&!(h==0&&w==0)){
        //vpii.clear();
        vpiiSize=0;
        memset(isExited,0,sizeof(isExited));
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                scanf("%c",&field[i][j]);
                //cin>>field[i][j];
                if(field[i][j]=='E'){
                    gy=i;
                    gx=j;
                    field[i][j]='.';
                }
                else if(field[i][j]=='@'){
                    sy=i;
                    sx=j;
                    field[i][j]='.';
                }
                else if(field[i][j]=='c'){
                    vpii[vpiiSize].first=i;
                    vpii[vpiiSize].second=j;
                    vpiiSize++;
                }
            }
            char tmp;
            scanf("%c",&tmp);
        }
        int res=dfs(sx,sy);
        if(res==INF)
            printf("%d\n",-1);
        else
            printf("%d\n",res);
    }
    return 0;
}

Measured memory_bytes: 964