#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
using namespace std;

typedef vector <string> VS;
typedef pair <int, int> PII;
typedef set <PII> Positions;
typedef pair <Positions, Positions> PPP;
typedef pair <PPP, PII> PVP;
typedef pair <int, PVP> Node;
typedef priority_queue <Node, vector<Node>, greater<Node> > Queue;
typedef set <PVP> Set;
const int dr[4] = { 0, 0, 1, -1 };
const int dc[4] = { 1, -1, 0, 0 };

int H, W;
bool O[11][11];

int solve( PPP initM, int sr, int sc, int gr, int gc ) {
    Set S;
    Queue Q;
    Node start( 0, PVP( initM, PII( sr, sc ) ) );
    Q.push( start );

    while ( !Q.empty() ) {
        Node node = Q.top();
        Q.pop();

        int cost = node.first;
        Positions panels = node.second.first.first;
        Positions cons = node.second.first.second;
        int r = node.second.second.first;
        int c = node.second.second.second;

        if ( r == gr && c == gc ) {
            return cost;
        }

        for ( int i = 0; i < 4; i++ ) {
            int nr = r + dr[i];
            int nc = c + dc[i];
            if ( nr < 0 || nr >= H || nc < 0 || nc >= W ) continue;

            if ( O[nr][nc] ) {
                continue;
            } else if ( panels.count( PII( nr, nc ) ) ) {
                continue;
            } else if ( cons.count( PII( nr, nc ) ) ) {
                int nnr = nr;
                int nnc = nc;
                for ( int j = 0;; j++ ) {
                    nnr += dr[i];
                    nnc += dc[i];
                    if ( O[nnr][nnc] || cons.count( PII( nnr, nnc ) ) ) {
                        nnr -= dr[i];
                        nnc -= dc[i];
                        PPP nextM( panels, cons );
                        nextM.second.erase( PII( nr, nc ) );
                        nextM.second.insert( PII( nnr, nnc ) );
                        Node nextnode( cost, PVP( nextM, PII( r, c ) ) );
                        if ( S.find( nextnode.second ) != S.end() ) break;
                        S.insert( nextnode.second );
                        Q.push( nextnode );
                        break;
                    }
                    else if ( panels.count( PII( nnr, nnc ))) {
                        PPP nextM( panels, cons );
                        nextM.second.erase( PII( nr, nc ) );
                        nextM.first.erase( PII( nnr, nnc ) );
                        Node nextnode( cost, PVP( nextM, PII( r, c ) ) );
                        if ( S.find( nextnode.second ) != S.end() ) break;
                        S.insert( nextnode.second );
                        Q.push( nextnode );
                        break;
                    }
                }
            } else if ( !O[nr][nc] ) {
                int ncost = cost + 1;
                Node nextnode( ncost, PVP( PPP( panels, cons ), PII( nr, nc ) ) );
                if ( S.find( nextnode.second ) != S.end() ) continue;
                S.insert( nextnode.second );
                Q.push( nextnode );
            }
        }
    }

    return -1;
}

int main() {
    while ( cin >> H >> W ) {
        if ( H == 0 && W == 0 ) break;

        VS lines(H);
        for ( int i = 0; i < H; i++ ) {
            cin >> lines[i];
        }

        for ( int i = 0; i < H; i++ ) {
            for ( int j = 0; j < W; j++ ) {
                O[i][j] = false;
            }
        }

        Positions panels;
        Positions cons;
        int sr, sc;
        int gr, gc;
        for ( int i = 0; i < H; i++ ) {
            for ( int j = 0; j < W; j++ ) {
                if ( lines[i][j] == '#' ) {
                    O[i][j] = true;
                } else if ( lines[i][j] == '@' ) {
                    sr = i;
                    sc = j;
                } else if ( lines[i][j] == 'E' ) {
                    gr = i;
                    gc = j;
                } else if ( lines[i][j] == 'w' ) {
                    panels.insert( PII( i, j ) );
                } else if ( lines[i][j] == 'c' ) {
                    cons.insert( PII( i, j ) );
                }
            }
        }

        cout << solve( PPP( panels, cons ), sr, sc, gr, gc ) << endl;
    }
}

Measured memory_bytes: 13000