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

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;


const int TOP = 0;
const int BOTTOM = 1;
const int LEFT = 2;
const int BACK = 3;
const int RIGHT = 4;
const int FRONT = 5;
class Saikoro {
public:
    int V[6]; 
    bool nullType;
    Saikoro( int a, int b ) {
        V[TOP] = a;
        V[BOTTOM] = 7 - a;
        V[FRONT] = b;
        V[BACK] = 7 - b;
        const int T[6][4] = {
            { 2, 3, 5, 4 },
            { 1, 4, 6, 3 },
            { 6, 5, 1, 2 },
            { 1, 5, 6, 2 },
            { 3, 6, 4, 1 },
            { 3, 2, 4, 5 }
        };
        for ( int i = 0; i < 4; ++ i ) {
            if ( T[a-1][i] == b ) {
                int left = i - 1;
                if ( left < 0 ) left = 3;
                V[LEFT] = T[a-1][left];
                break;
            }
        }
        V[RIGHT] = 7 - V[LEFT];
        nullType = false;
    }
    int getV( int dir ) {
        return V[2+dir];
    }
    int getTop() {
        return V[TOP];
    }
    int getBottom() {
        return V[BOTTOM];
    }
    void rollLeft() {
        int NV[6];
        NV[FRONT] = V[FRONT];
        NV[BACK] = V[BACK];
        NV[LEFT] = V[TOP];
        NV[TOP] = V[RIGHT];
        NV[RIGHT] = V[BOTTOM];
        NV[BOTTOM] = V[LEFT];
        for ( int i = 0; i < 6; ++ i ) V[i] = NV[i];
    }
    void rollRight() {
        int NV[6];
        NV[FRONT] = V[FRONT];
        NV[BACK] = V[BACK];
        NV[LEFT] = V[BOTTOM];
        NV[BOTTOM] = V[RIGHT];
        NV[RIGHT] = V[TOP];
        NV[TOP] = V[LEFT];
        for ( int i = 0; i < 6; ++ i ) V[i] = NV[i];
    }
    void rollFront() {
        int NV[6];
        NV[LEFT] = V[LEFT];
        NV[RIGHT] = V[RIGHT];
        NV[FRONT] = V[TOP];
        NV[TOP] = V[BACK];
        NV[BACK] = V[BOTTOM];
        NV[BOTTOM] = V[FRONT];
        for ( int i = 0; i < 6; ++ i ) V[i] = NV[i];
    }
    void rollBack() {
        int NV[6];
        NV[LEFT] = V[LEFT];
        NV[RIGHT] = V[RIGHT];
        NV[FRONT] = V[BOTTOM];
        NV[BOTTOM] = V[BACK];
        NV[BACK] = V[TOP];
        NV[TOP] = V[FRONT];
        for ( int i = 0; i < 6; ++ i ) V[i] = NV[i];
    }
    void roll( int dir ) {
        if ( dir == 0 ) rollLeft();
        if ( dir == 1 ) rollBack();
        if ( dir == 2 ) rollRight();
        if ( dir == 3 ) rollFront();
    }
    Saikoro() {
        nullType = true;
    }
};

bool operator < ( const Saikoro& a , const Saikoro& b ) {
    VI ad = VI( a.V, a.V+6 ), bd = VI( b.V, b.V+6 );
    return ad < bd;
}
 
ostream& operator << ( ostream& os, Saikoro s ) {
    const string T[6] = { "TOP", "BOTTOM", "LEFT", "BACK", "RIGHT", "FRONT" };
    os << "{";
    for ( int i = 0; i < 6; ++ i ) {
        os << T[i] << ":" << s.V[i];
        if ( i + 1 < 6 ) os << ", ";
    }
    os << "}";
    return os;
}

const int SIZE = 11;
int h, w;
int M[SIZE][SIZE];
int sr, sc, gr, gc;

bool input() {
    if ( ! ( cin >> h >> w && h ) ) return false;
    for ( int i = 0; i < h; ++ i ) {
        for ( int j = 0; j < w; ++ j ) {
            cin >> M[i][j];
        }
    }
    cin >> sr >> sc >> gr >> gc;
    return true;
}

typedef pair <II, Saikoro> STATE;
typedef pair <int, STATE> NODE;
typedef priority_queue <NODE, vector<NODE>, greater<NODE> > QUEUE;
const int dr[4] = { 0, -1, 0, 1 };
const int dc[4] = { -1, 0, 1, 0 };
typedef map <STATE, int> MIN_COST;
MIN_COST MC;
QUEUE Q;

bool is_min( int next_steps, STATE s ) {
    if ( MC.count(s) ) return next_steps < MC[s];
    return true;
}

int solve() {
    STATE start_state( II( sr, sc ), Saikoro( 1, 2 ) );
    Q = QUEUE();
    Q.push( NODE( 0, start_state ) );
    MC.clear();

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

        int steps = node.first;
        int r = node.second.first.first;
        int c = node.second.first.second;
        Saikoro s = node.second.second;

        if ( r == gr && c == gc ) return steps;

        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;
            Saikoro ns = s;
            ns.roll(i);
            int nsteps = steps + M[nr][nc] * ns.getBottom();
            STATE nstate( II( nr, nc ), ns );
            if ( ! is_min( nsteps, nstate ) ) continue;
            MC[nstate] = nsteps;
            NODE next( nsteps, nstate );
            Q.push( next );
        }
    }
    
    return -1;
}

int main() {
    while ( input() ) {
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 1328