#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef long long ll;

const int MAX_SIZE = 10000;

struct edge{
	int x;
	int y;
	int under;
	int over;
	int cost;
};

typedef pair<int,int> P;
int V;

const int MAX_V = 5000;

// y,x,ºÌÚ,ãÌÚ
vector<edge> G[10][10][7][7];
int d[10][10][7][7];
const int INF = 100000000;

int h,w;

int field[10][10];

class Situation{
public:
	int x,y,under,over;
	int cost;
	Situation(int x_,int y_,int under_,int over_,int cost_){
		x = x_;
		y = y_;
		under = under_;
		over = over_;
		cost = cost_;
	}
	bool operator<(const Situation &s)const{
		return s.cost < this->cost;
	}
};


void dijkstra(int x,int y,int under,int over){
	priority_queue<Situation> que;
	for(int i = 0; i < 10; i++)
		for(int j = 0; j < 10; j++)
			for(int k = 0; k < 7; k++)
				fill(d[i][j][k],d[i][j][k]+7,INF);

	d[y][x][under][over] = 0;
	que.push(Situation(x,y,under,over,0));
	while(!que.empty()){
		Situation p = que.top();
		que.pop();
		int cx = p.x;
		int cy = p.y;
		int cu = p.under;
		int co = p.over;

		if(d[cy][cx][cu][co] < p.cost)
			continue;
		for(int i = 0; i < G[cy][cx][cu][co].size(); i++){
			edge e = G[cy][cx][cu][co][i];
			int cost = field[e.y][e.x]*e.under;
			if(d[e.y][e.x][e.under][e.over] > d[cy][cx][cu][co] + cost){
				d[e.y][e.x][e.under][e.over] = d[cy][cx][cu][co] + cost;
				que.push(Situation(e.x,e.y,e.under,e.over,d[e.y][e.x][e.under][e.over]));
			}
		}
	}
}

int main(){

	while(cin >> h >> w && !(h==0&&w==0)){
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin>>field[i][j];
			}
		}
		pair<int,int> start,goal;
		cin >> start.first >> start.second;
		cin >> goal.first >> goal.second;

		// edgeðÔ
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				for(int k = 0; k < 7; k++){
					for(int l = 0; l < 7; l++)
						G[i][j][k][l].clear();
				}
			}
		}

		int dy[]={-1,0,0,1};
		int dx[]={0,-1,1,0};
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				// êÊÌÚ
				for(int k = 1; k < 7; k++){
					// ã¤ÊÌÚ
					for(int l = 1; l < 7; l++){
						if(k == l || k + l == 7)
							continue;
						for(int m = 0; m < 4; m++){
							pair<int,int> np;
							np.first = i + dy[m];
							np.second = j + dx[m];
							if(np.first >= 0 && np.second >= 0 && np.first < h && np.second < w){
								// »ÝÌ}XÌóµÉ¶Äedgeðãü
								edge e;
								e.x = np.second;
								e.y = np.first;
								// ãÉiÞê
								if(dy[m] == -1){
									e.under = l;
									e.over = 7-k;
								}
								// ºÉiÞê
								else if(dy[m] == 1){
									e.under = 7-l;
									e.over = k;
								}
								// ¶EÉiÞê
								else if(dx[m] == 1 || dx[m]==-1){
									e.over = l;
									if(k == 1 || k == 6){
										if(l == 2){
											e.under = 4;
										}
										else if(l == 3){
											e.under = 2;
										}
										else if(l == 5){
											e.under = 3;
										}
										else if(l == 4){
											e.under = 5;
										}
										if(k == 1){
											e.under = 7-e.under;
										}
									}
									else if(k == 2 || k == 5){
										if(l == 3){
											e.under = 6;
										}
										else if(l == 4){
											e.under = 1;
										}
										else if(l == 1){
											e.under = 3;
										}
										else if(l == 6){
											e.under = 4;
										}
										if(k==2){
											e.under = 7-e.under;
										}
									}
									else if(k == 3 || k == 4){
										if(l == 1){
											e.under =5;
										}
										else if(l == 2){
											e.under = 1;
										}
										else if(l == 5){
											e.under = 6;
										}
										else if(l==6){
											e.under = 2;
										}
										if(k==3){
											e.under = 7-e.under;
										}
									}
									if(dx[m]==-1){
										e.under = 7-e.under;								
									}
								}
								G[i][j][k][l].push_back(e);
							}
						}
					}
				}
			}
		}
		dijkstra(start.second,start.first,6,5);
		int minCost = 1000000000;
		for(int i = 1; i < 7; i++){
			for(int j = 1; j < 7; j++){
				minCost = min(minCost,d[goal.first][goal.second][i][j]);
			}
		}
		cout<<minCost<<endl;
	}
	
	return 0;
}