#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps = 1e-9;

enum R_Way {
	R_Left,
	R_Front,
	R_Right,
	R_Back,

	R_Dummy,
};
struct Dice {
	int tp;
	int bo;
	int no;
	int so;
	int ea;
	int we;
	Dice(int tp_, int bo_, int no_, int so_, int ea_, int we_) :
		tp(tp_), bo(bo_), no(no_), so(so_), ea(ea_), we(we_) {

	}
	Dice(vector<int>pips_) {

	}

	Dice() {
		tp = 1;
		bo = 6;
		no = 5;
		so = 2;
		ea = 3;
		we = 4;
	}

	int rotate(const R_Way way) {
		switch (way) {
		case R_Right: {
			int c = tp;
			tp = we;
			we = bo;
			bo = ea;
			ea = c;
		}
					  break;
		case R_Back: {
			int c = tp;
			tp = so;
			so = bo;
			bo = no;
			no = c;
		}
					 break;
		case R_Left: {
			int c = tp;
			tp = ea;
			ea = bo;
			bo = we;
			we = c;
		}
					 break;
		case R_Front: {
			int c = tp;
			tp = no;
			no = bo;
			bo = so;
			so = c;
		}
					  break;
		default:
			assert(false);
		}
		return tp;
	}
	int rotate(const int way) {
		return rotate(static_cast<R_Way>(way));
	}
	void spin(const int  clockwise) {
		if (!clockwise) {

			rotate(R_Way::R_Left);
			rotate(R_Way::R_Back);
			rotate(R_Way::R_Right);
		}
		else {

			rotate(R_Way::R_Left);
			rotate(R_Way::R_Front);
			rotate(R_Way::R_Right);
		}
	}
	int hash()const {
		return tp + we * 6 + no * 36;
	}
};
int geteast(int top, int south) {
	map<pair<int, int>, int>mp;
	mp[make_pair(1, 2)] = 3;
	mp[make_pair(1, 3)] = 5;
	mp[make_pair(2, 3)] = 1;
	mp[make_pair(2, 4)] = 6;
	bool rev = false;
	if (top >= 4) {
		rev = !rev; top = 7 - top;
	}
	if (south >= 4) {
		rev = !rev; south = 7 - south;
	}
	if (top > south) {
		rev = !rev; swap(top, south);
	}
	return mp[make_pair(top, south)];
}

int gettop(int south, int east) {
	return geteast(south, east);
}
int getsouth(int east, int top) {
	return 7 - geteast(top, east);
}
bool operator==(const Dice&l, const Dice&r) {
	return l.hash() == r.hash();
}

int H, W;
bool check(const int y, const int x) {
	return y >= 0 && y < H&&x >= 0 && x < W;
}
struct aa {
	int x;
	int y;
	int tp;
	int bo;
	int no;
	int so;
	int ea;
	int we;
	int hash;
	int time;
};
class Compare {
public:
	bool operator()(const aa&l, const aa&r) {
		return l.time> r.time;
	}
};	//aa?????????????????¶

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

int memo[101][101][1000];
int main() {
	map<int, int>mp;
	int num = 0;
	while (1) {
		for (int i = 0; i < 100; ++i) {
			for (int j = 0; j < 100; ++j) {
				for (int k = 0; k < 1000; ++k) {
					memo[i][j][k] = 1e8;
				}
			}
		}
		cin >> H >> W;
		if (!H)break;
		vector<vector<int>>field(H, vector<int>(W));
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				cin >> field[i][j];
			}
		}
		int sx, sy, gx, gy; cin >> sy >> sx >> gy >> gx;
		

		priority_queue<aa, vector<aa>, Compare>que;
		Dice ini_di;
		que.push(aa{ sx,sy,ini_di.tp,ini_di.bo,ini_di.no,ini_di.so,ini_di.ea,ini_di.we,ini_di.hash(),0 });
		int ans = -1;
		while (!que.empty()) {
			aa atop(que.top());
			que.pop(); if (atop.x == gx&&atop.y == gy) {
				ans = atop.time;
				break;
			}
			for (int way = 0; way < 4; ++way) {
				const int nextx = atop.x + dx[way];
				const int nexty = atop.y + dy[way];
				
				Dice di = Dice(atop.tp, atop.bo, atop.no, atop.so, atop.ea, atop.we);
				if (check(nexty, nextx)) {
					di.rotate(way);
					const int nexttime=  atop.time + di.bo*field[nexty][nextx];
					if (mp.find(di.hash()) == mp.end()) {
						mp[di.hash()] = num++;
					}
					if (memo[nextx][nexty][mp[di.hash()]]>nexttime) {
						memo[nextx][nexty][mp[di.hash()]] = nexttime;
						que.push(aa{ nextx,nexty,di.tp,di.bo,di.no,di.so,di.ea,di.we,di.hash(),nexttime });
					}
				}
				else {
					continue;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}