#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

enum direction{
  UP    = 0,
  RIGHT = 1,
  DOWN  = 2,
  LEFT  = 3
};

/*
 *   6
 *   2
 * 3 1 4
 *   5
 */

/* top and RIGHT */
int next_top[7][7][4];
int next_left[7][7][4];
int front[7][7];

void initDie(){
  front[1][3] = 2; front[1][2] = 4; front[1][4] = 5; front[1][5] = 3;
  front[2][1] = 3; front[2][3] = 6; front[2][4] = 1; front[2][6] = 4;
  front[3][1] = 5; front[3][2] = 1; front[3][5] = 6; front[3][6] = 2;
  for(int i = 4; i < 7; i++){
    for(int j = 1; j < 7; j++){
      if(i == j || i + j == 7) continue;
      int t = 7 - i;
      int l = 7 - j;
      front[i][j] = front[t][l];
    }
  }

  for(int t = 1; t < 7; t++){
    for(int l = 1; l < 7; l++){
      if(t == l || t + l == 7) continue;

      next_top[t][l][UP]     = 7 - front[t][l];
      next_top[t][l][LEFT]   = 7 - l;
      next_top[t][l][RIGHT]  = l;
      next_top[t][l][DOWN]   = front[t][l];

      next_left[t][l][UP]    = l;
      next_left[t][l][LEFT]  = t;
      next_left[t][l][RIGHT] = 7 - t;
      next_left[t][l][DOWN]  = l;
    }
  }
}

int b[10][10];
int memo[10][10][7][7];

int main(){
  int h,w;

  initDie();

  while((h = getInt()) + (w = getInt())){
    REP(i,h) REP(j,w) b[i][j] = getInt();
    int sy = getInt();
    int sx = getInt();
    int gy = getInt();
    int gx = getInt();
    typedef pair<int, pair<pair<int,int>,pair<int,int> > > data;
    priority_queue<data,vector<data>,greater<data> > pq;

    pq.push(mp(0, mp( mp(sx,sy), mp(1, 4))));
    memset(memo, -1, sizeof(memo));

    while(pq.size()){
      data d = pq.top(); pq.pop();
      int cost = d.f;
      int x = d.s.f.f;
      int y = d.s.f.s;
      int t = d.s.s.f;
      int l = d.s.s.s;

      //printf("cost = %d, (%d,%d) (%d,%d)\n",cost,x,y,t,l);

      if(x == gx && y == gy){
        print(cost);
        break;
      }

      if(memo[x][y][t][l] != -1)
        continue;

      memo[x][y][t][l] = cost;

      REP(i,4){
        int xx = x + _dx[i];
        int yy = y + _dy[i];
        if(!ISIN(xx,yy,w,h)) continue;
        int tt = next_top[t][l][i];
        int ll = next_left[t][l][i];

        int cc = cost + (7 - tt) * b[yy][xx];

        if(memo[xx][yy][tt][ll] == -1)
          pq.push(mp(cc, mp( mp(xx,yy), mp(tt,ll))));
      }
    }
  }
  return 0;
}

Measured memory_bytes: 936