#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cassert>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
int h,w,imap[20][20];
P s,g;         
const int dx[4] = {0,1,0,-1};//0:ツ可コツ、1:ツ右ツ、2:ツ湘」ツ、3:ツ債カ
const int dy[4] = {1,0,-1,0};
//bool used[20][20];
int dpused[20][20];
int candidate;
int dice[6] = {1,2,4,5,3,6};//0:top,1:front,2:left,3:back,4:right,5:bottom

int Reverse(int p){
  if(p == 0)return 2;
  if(p == 1)return 3;
  if(p == 2)return 0;
  if(p == 3)return 1;
}
/*
void RollMe(int face){ //enomoto
  if(face == 0){
    int h = dice[3];
    dice[3] = dice[5];
    dice[5] = dice[1];
    dice[1] = dice[0];
    dice[0] = h;
  }
  else if(face == 1){
    int h = dice[0];
    dice[0] = dice[2];
    dice[2] = dice[5];
    dice[5] = dice[4];
    dice[4] = h;
  }
  else if(face == 2){
    int h = dice[0];
    dice[0] = dice[1];
    dice[1] = dice[5];
    dice[5] = dice[3];
    dice[3] = h;
  }
  else if(face == 3){
    int h = dice[0];
    dice[0] = dice[4];
    dice[4] = dice[5];
    dice[5] = dice[2];
    dice[2] = h;
  }
}
*/

/* //ツづ?/ツづ?暗債づ慊づェツづ?つ「ツづゥツづ?づ個づ債使ツ用ツつオツづ按つ「*/
/*ツ　
void rec(P p,int sam){
  //cout << "Pos = " << p.F << " " << p.S << ",sam = " << sam << endl;  
  if(p == g){
    candidate = min(candidate,sam);
    return;
  }
  for(int i=0;i<4;i++){
    int nx = p.F+dx[i],ny = p.S+dy[i];
*/
//if(/*!used[ny][nx] &&*/// !(0<=nx && nx<w && 0<=ny && ny <h))continue;
    //cout << "nx = " << nx << " ny = "  << ny << endl;//
//      RollMe(i);
//if( dpused[ny][nx] > (sam+imap[ny][nx]*dice[5]) ){
      //used[ny][nx] = true;//
      //RollMe(i);//
      //dpused[ny][nx] = sam+imap[ny][nx]*dice[5];
	//rec(P(nx,ny),dice[5]*imap[ny][nx]+sam);
      //RollMe(Reverse(i));//
      //used[ny][nx] = false;//
      //  }
//    RollMe(Reverse(i));
//}
//}


int idx(int tp,int ft){
  return tp*10+ft;
}


struct special{
  int x,y,top,front,left,back,right,bottom,cost;
  //special (int x,int y,int top,int front,int left,int back,int right,int bottom,int cost):x(x),y(y),top(top),front(front),left(left),back(back),right(right),bottom(bottom),cost(cost){}

  bool operator < (const special &p)const{
    return cost > p.cost;
  }

 

  //0->top, 1->front, 2->left, 3->back, 4->right, 5->bottom
void RollMe(int face){ //enomoto
  if(face == 0){
    int h = back;
    back = bottom;
    bottom = front;
    front = top;
    top = h;
  }
  else if(face == 1){
    int h = top;
    top = left;
    left = bottom;
    bottom = right;
    right = h;
  }
  else if(face == 2){
    int h = top;
    top = front;
    front = bottom;
    bottom = back;
    back = h;
  }
  else if(face == 3){
    int h = top;
    top = right;
    right = bottom;
    bottom= left;
    left = h;
  }
}


};
int D[20][20][100];
const int INF = 1<<30;
int main(){
  while(cin >> h >> w && h && w){
    candidate = INF;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)cin >> imap[i][j];
    }
    cin >> s.S >> s.F;
    cin >> g.S >> g.F;
    for(int i=0;i<h;i++)for(int j=0;j<w;j++){//used[i][j] = false;
	//	dpused[i][j] = INF;
	for(int k=0;k<100;k++)D[i][j][k] = INF;
      }
  
    //used[s.S][s.F] = true;
    //dpused[s.S][s.F] = 0;
    //rec(s,0);
    D[s.S][s.F][idx(1,2)]=0;
    priority_queue<special>que;
    special In;
    //int dice[6] = {1,2,4,5,3,6};//0:top,1:front,2:left,3:back,4:right,5:bottom
    In.x = s.F;In.y = s.S; In.top = 1;In.front = 2;In.left = 4;In.back = 5;In.right = 3;In.bottom = 6; In.cost = 0;
    que.push(In);
    //special - > x,y,top,front,left,back,right,bottom,cost;
    while(!que.empty()){
      special pos = que.top(); que.pop();
      //majesty
      if(pos.x == g.F && pos.y == g.S){
	candidate = min(candidate,pos.cost);
	break;
      }

      for(int i=0;i<4;i++){
	int nx = pos.x+dx[i],ny = pos.y+dy[i];

	if(!(0<=nx && nx <w && 0<= ny && ny <h))continue;
	pos.RollMe(i);       

	if(D[ny][nx][idx(pos.top,pos.front)] > imap[ny][nx]*pos.bottom+ pos.cost){
	  D[ny][nx][idx(pos.top,pos.front)] = imap[ny][nx]*pos.bottom+ pos.cost;
	  In.x = nx;In.y = ny;In.top = pos.top;In.front = pos.front;In.back = pos.back;In.left = pos.left; In.right = pos.right; In.bottom = pos.bottom; In.cost =  imap[ny][nx]*pos.bottom+ pos.cost;
	  que.push(In);
	}
	  pos.RollMe(Reverse(i));

      }

    }

    /*
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)cout << dpused[i][j] << " ";
      cout << endl;
    }
    */
    assert(candidate != INF);
    cout << candidate << endl;
  }
  return 0;
}


















































































/*

class Point{
public:
  double x,y;
  Point(double x =0,double y=0):x(x),y(y){}
  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(x*a,y*a);}
  Point operator / (double a){return Point(x/a,y/a);} //ツづ?つオツ按ォツづーツ使ツつ、ツづ按づァツ要ツ確ツ認

  double norm() {return x*x+y*y;}
  double abs() {return sqrt(norm());}

  bool operator < (const Point &p) const{
    return x != p.x ? x < p.x : y < p.y; 
  }

  bool operator == (const Point &p) const{
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};
typedef Point Point;
struct Segment{
public:
  Point p1,p2;
  Segment(Point p = Point(),Point pp = Point()):p1(p),p2(pp){}
};

typedef vector<Point> Polygon;
typedef Segment Line;

Point ACM,IC,PC;
Segment IC_PC,PC_ACM,ACM_IC;



double norm(Point p){
  return p.x*p.x+p.y*p.y;
}

double abs(Point p){
  return sqrt(norm(p));
}

Point polar(double a,double rad){
  return Point(a*cos(rad),a*sin(rad));
}

double args(Point p){
  return atan2(p.y,p.x);
}

double dot(Point a,Point b){
  return a.x*b.x+a.y*b.y;
}

double cross(Point a,Point b){
  return a.x*b.y-b.x*a.y;
}

Point project(Segment s,Point p){
  Point base = s.p2 - s.p1;
  double t = dot(p-s.p1,base)/base.norm();
  return s.p1+base*t;
}

Point reflect (Segment s, Point p){
  return p + (project(s,p)-p)*2.0;
}

int ccw(Point p0,Point p1,Point p2){
  Point a = p1-p0;
  Point b = p2-p0;
  if(cross(a,b) > EPS) return COUNTER_CLOCKWISE;
  if(cross(a,b) < -EPS) return CLOCKWISE;
  if(dot(a,b) < -EPS) return ONLINE_BACK;
  if(a.norm() < b.norm() ) return ONLINE_FRONT;
  return ON_SEGMENT;
}

 */






















































































































































 /*memo:
ツ渉可甘コツバツーツジツδ?δ督つセツづ?催?帰ツづ?枝ツ静伉づィツづーツつオツづつづつづ個探ツ催オツづーツつィツつアツづ按づ?づ?つ「ツつス
dpusedツづ?つ「ツつ、ツ配ツ療アツづ可つサツつアツづ個マツスツづ慊づ?つュツづゥツ催?短ツコツスツトツづーツ陛崢堕カツつオツ、ツ催?度ツつサツづ個マツスツづ可督楪陳?つオツつスツ催崢づ嬰pusedツづ個値ツづヲツづィツづ?渉ャツつウツつ「ツづ個づ?つ?づェツづ篠更ツ新ツつキツづゥツづ?つ「ツつ、ツ陛サツ針ツづ?つ?づゥ
ツつオツつゥツつオwツづ?ツつェツ妥・ツつォツつ「ツづ?（?ツ　ツ陳?甘板づ債つスツづ淞つオツづ?つ「ツづ按つ「ツつェ4*4ツつ?つスツづィツづ慊づ?づ債つ、ツづ慊つュツつ「ツつュツ様ツ子)ツ催?渉ャツコツスツトツつェツ本ツ猟按づ個催?渉ャツコツスツトツづヲツづィツづ「ツづ「ツ妥・ツつォツつュツづ按づゥ
ツつ?づゥツマツスツつゥツづァツつ?づゥツマツスツづ慊づ?暗堋督ョツつオツつスツ催崢づ可づ?つ、ツつ「ツつ、ツ経ツ路ツづ?暗堋督ョツつオツづヲツつ、ツつェツ督楪陳?つオツつスツ催崢づ個サツイツコツδ債づ個湘ウツ仰オツづ債暗ェツ渉渉づ可づ按づゥツづ?考ツつヲツづ?つ「ツつスツづ個つセツつェツつサツつ、ツづ?づ債づ按つ「ツづ個つセツづォツつ、ツつゥ
(0,0)->(1,0)ツづー(0,0)->(0,1)->(1,1)->(1,0)ツづ?暗堋督ョツつオツづ?づ?個仰凝?づ?0,0)->(0,1)->(0,0)->(1,0)ツづ?暗ェツ渉渉づ?サツイツコツδ債づ個湘ウツ妥板づ債つゥツづュツづァツづ按つ「ツづヲツつ、ツづ按気ツづ?つキツづゥ
ツサツイツコツδ債づ個湘ウツ妥板つェツつゥツづュツづァツづ按つ「ツづ個づ?つ?づェツづ篠余ツ計ツづ可暗堋督ョツつキツづゥツ閉ェツコツスツトツつェツつゥツつゥツづゥツづ個づ?鳴ウツ妥環づ?つ?づゥ
ツづ?つオツ０ツづ個マツスツつェツつ?づィツ可督嘉アツづィツつオツづ?暗堋督ョツつキツづゥツづ?コツスツトツつェツ渉ャツつウツつュツづ按づゥツづ個づ?つ?づェツづ篠、ツコツスツトツつェツ渉ャツつウツつュツづ按づゥツづ?つ「ツつ、ツ湘ーツ個渉づーツ鳴楪つスツつオツづ?つ「ツづゥツづ個づ?姪「ツ妥ィツづ按つュツ更ツ新ツつウツづェツづゥツづ個つセツつェツ、WAツづ?つ?づ?つス

ツつアツづェツづ慊づ?づ債経ツ路ツづ可甘鳴係ツづ按つュツサツイツコツδ債づ個湘ウツ妥板づ債督ッツつカツづ?つオツづ?つォツつスツつェツつ、ツづ慊つュツつ「ツつゥツづ按つ「ツづ個づ?考ツつヲツづーツ嘉シツづ淞つス
ツ暗環置ツつセツつッツづ?催?渉ャツコツスツトツづーツ甘?猟敖つオツづ?つォツつスツつェツつウツづァツづ可サツイツコツδ債づ個湘ウツ妥板づーツ津?嘉?つオツづДPツづーツ行ツつ、ツつアツづ?づ?つオツつス
ツサツイツコツδ債づ可甘鳴つキツづゥツ渉按猟敖づ債渉可甘コツバツーツジツδ?δ督づ個づ?づ個づーツ猟ャツ用ツ、ツ新ツつスツづ按陛サツ法ツづ?渉可甘コツバツーツジツδ?δ督づ可サツイツコツδ債づ個湘ウツ妥板づーツつュツづュツつヲツづゥツつセツつッツづ按づ個づ?つウツづ卍づ?篠楪甘板づ債要ツつウツづ按つ「

ツづ按つコツサツイツコツδ債づ個湘ウツ妥板つェツづ按つ「ツづ?つ、ツづ慊つュツつ「ツつゥツづ按つゥツづ按づ?つスツづ個つセツづォツつ、ツつゥ
ツづ?つ、ツつ「ツづ?つスツ湘ェツ債?づ可板スツ療。ツつェツつ?づゥツづ個つゥ
ツ篠?づ個個サツ催敖づ個療債づ?づ?0*10ツづ個マツスツづ個個仰嘉環づーツ脳ツ禿?シツδ?ミツδ個ーツシツδ?δ督づ?づ債つセツつキツつアツづ?つェツづ?つォツづ按つ「ツ湘」ツづ可、ツノツーツトツづ可渉堕つュツづ個づ?渉ュツ々ツ姪環倒ツづ按づ個づ?参ツづ?つスツづ?づ個づ?つ?づゥ

ツ素ツ陳シツづ可サツイツコツδ債づ個購ツ禿シツづーツつオツづヲツつ、ツづ?思ツつ、

ツ板スツ療。ツづーツ嘉ッツ津δづ可帰ツづゥツづ慊づ?づ可個ゥツづつつッツづェツづ按つッツづェツづ篠誰ツつゥツづ可閉キツつ「ツづ?づ敖づヲツつ、
   */

Measured memory_bytes: 1328