#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


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

#define roll_swap(x, a, b, c, d) swap(x.a, x.b), swap(x.b, x.c), swap(x.c, x.d);
struct Dice {
    int top, front, right, left, back, bottom;
    
    Dice(int to = 1, int fr = 2, int ri = 3, int le = 4, int ba = 5, int bo = 6) 
    : top(to), front(fr), right(ri), left(le), back(ba), bottom(bo) { }
    void roll_right() { roll_swap((*this), top, left, bottom, right); }
    void roll_left() { roll_swap((*this), top, right, bottom, left); }
    void roll_front() { roll_swap((*this), top, back, bottom, front); }
    void roll_back() { roll_swap((*this), top, front, bottom, back); }
    void roll_cw() { roll_swap((*this), back, left, front, right); }
    void roll_ccw() { roll_swap((*this), back, right, front, left); }
    void roll(int dir) {
        if (dir == 0) (*this).roll_front();
        if (dir == 1) (*this).roll_right();
        if (dir == 2) (*this).roll_back();
        if (dir == 3) (*this).roll_left();
    }
    friend bool operator < (const Dice &d1, const Dice &d2) {
        int vd1[] = {d1.top, d1.front, d1.right, d1.left, d1.back, d1.bottom};
        int vd2[] = {d2.top, d2.front, d2.right, d2.left, d2.back, d2.bottom};
        return vector<int>(vd1, vd1 + 6) < vector<int>(vd2, vd2 + 6);
    }
    friend ostream& operator << (ostream& s, const Dice& d) { 
        return s << '<' << d.top << ',' << d.front << ',' << d.right << '>'; 
    }
};

vector<Dice> all_rotate() {
    vector<Dice> res(24);
    Dice d;
    for (int i = 0; i < 6; ++i) {
        for (int j = 0; j < 4; j++) {
            res[i * 4 + j] = d;
            d.roll_cw();
        }
        if (i & 1) d.roll_front();
        else d.roll_right();
    }
    return res;    
}

const int INF = 1<<29;

int n, m;
int fi[15][15];
int sx, sy, tx, ty;

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    
    vector<Dice> vd = all_rotate();
    map<Dice,int> ma;
    for (int i = 0; i < vd.size(); ++i) ma[vd[i]] = i;
    
//    COUT(vd);
//    COUT(ma);
    
    while (cin >> n >> m) {
        if (n == 0) break;
        for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> fi[i][j];
        cin >> sx >> sy >> tx >> ty;
        
        int dp[15][15][31];
        for (int i = 0; i < 15; ++i) for (int j = 0; j < 15; ++j) for (int k = 0; k < 31; ++k) dp[i][j][k] = INF;
        dp[sx][sy][0] = 0;
        priority_queue< pair<int,pair<pint,int> >, vector<pair<int,pair<pint,int> > >, greater<pair<int,pair<pint,int> > > > que;
        que.push( MP(0, MP(pint(sx,sy), 0)) );
        while (!que.empty()) {
            //cout << que.top() << endl;
            
            int dist = que.top().first;
            int x = que.top().second.first.first;
            int y = que.top().second.first.second;
            int id = que.top().second.second;
            Dice d = vd[id];
            que.pop();
            
            if (dist > dp[x][y][id]) continue;
            
            for (int i = 0; i < 4; ++i) {
                int nx = x + dx[i], ny = y + dy[i];
                if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
                Dice nd = d;
                nd.roll(i);
                int nid = ma[nd];
                
                int add = nd.bottom * fi[nx][ny];
                int ndist = dist + add;
                if (chmin(dp[nx][ny][nid], ndist)) {
                    que.push( MP(ndist, MP(pint(nx,ny),nid)) );
                }
            }
        }
        
        int Min = INF;
        for (int i = 0; i < 24; ++i) chmin(Min, dp[tx][ty][i]);
        
        cout << Min << endl;
    }
    return 0;
}


Measured memory_bytes: 1244