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

int H[6][6] = {
    {1,5,2,3,0,4}, // North : 奥へ移動   ( y:-1 )
    {3,1,0,5,4,2}, // East  : 右へ移動   ( x:+1 )
    {2,1,5,0,4,3}, // West  : 左へ移動   ( x:-1 )
    {4,0,2,3,5,1}, // South : 手前へ移動 ( y:+1 )
    {0,2,4,1,3,5}, // Right : 右回りに回転 (移動なし)
    {0,3,1,4,2,5}  // Left  : 左回りに回転 (移動なし)
};

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

// サイコロライブラリ
// d[0] := top,   d[1] := front 
// d[2] := right, d[3] := left
// d[4] := back,  d[5] := bottom
enum{TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM};
struct Cube{
    vector<int> d;
    // コンストラクタで初期化
    Cube(vector<int> v){
        if( v.size() == 6 )
            d = v;
        else
            d = vector<int>(6);
    }
    Cube(){ d = vector<int>(6); }
    // dirの方向に回転 (副作用なし)
    Cube roll(int dir) const {
        vector<int> d_(6);
        for(int i = 0 ; i < 6 ; i++ ){
            d_[i] = d[ H[dir][i] ];
        }
        return Cube(d_);
    }
};
// Cube の順序を定義 (map<Cube,T> を使いたいとき用)
bool operator<(const Cube& a, const Cube& b){
    if( a.d[0] == b.d[0] )
        return a.d[1] < b.d[1];
    return a.d[0] < b.d[0];
}

const int INF = 1e+8;
int m[10][10];
int w, h, sx, sy, gx, gy;
// d[y][x][top][front] := (x,y) にサイコロの上面がtop, 正面がfrontだったときの最小コスト
int d[10][10][10][10];

struct State{
	Cube c;
	int x, y, cost;
	State(){}
	State(Cube c_, int x_, int y_, int cost_){
		c = c_; x = x_; y = y_; cost = cost_;
	}
};
bool operator<(const State& a, const State& b){
	return a.cost > b.cost;
}

int solve(){
	// 初期化
	for(int y=0 ; y < 10 ; y++ ){
		for(int x=0 ; x < 10 ; x++ ){
			for(int i=0 ; i < 10 ; i++ ){
				fill(d[y][x][i], d[y][x][i]+10, INF);
			}
		}
	}
	vector<int> v(6);
	for(int i=0 ; i < 6 ; i++ ){
		v[i] = i+1;
	}
	d[sy][sx][1][2] = 0;
	priority_queue<State> q;
	q.push( State(Cube(v), sx, sy, 0) );
	int res = INF;
	while( !q.empty() ){
		int x = q.top().x;
		int y = q.top().y;
		int cost = q.top().cost;
		Cube c = q.top().c;
		q.pop();
		
		if( x == gx && y == gy ){
			res = cost;
			break;
		}
		
		for(int i=0 ; i < 4 ; i++ ){
			int mx = x + dx[i];
			int my = y + dy[i];
			if( mx < 0 || my < 0 || w <= mx || h <= my ) continue;
			Cube next = c.roll(i);
			int next_cost = cost + next.d[BOTTOM] * m[my][mx];
			int top = next.d[TOP];
			int front = next.d[FRONT];
			if( next_cost < d[my][mx][top][front] ){
				d[my][mx][top][front] = next_cost;
				q.push( State(next, mx, my, next_cost) );
			}
		}
	}
	return res;
}

int main(){
	while( cin >> h >> w , h || w ){
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				cin >> m[y][x];
			}
		}
		cin >> sy >> sx >> gy >> gx;
		int ans = solve();
		cout << ans << endl;
	}
}