#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;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()
const int INF = 1<<29;

enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
template <class T>
class dice {
public:
  dice(T *v) {
    id[TOP] = 0; id[FRONT] = 1; id[LEFT] = 2;
    id[RIGHT] = 3; id[BACK] = 4; id[BOTTOM] = 5;
    REP(i,6)
      var[i] = v[i];
  }
  T& operator[] (FACE f) { return var[id[f]]; }
  const T& operator[] (FACE f) const { return var[id[f]]; }
  bool operator==(const dice<T>& b) const {
    const dice<T> &a = *this;
    return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
           a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
           a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
  }
  void roll_x() { roll(TOP, BACK, BOTTOM, FRONT); }
  void roll_y() { roll(TOP, LEFT, BOTTOM, RIGHT); }
  void roll_z() { roll(FRONT, RIGHT, BACK, LEFT); }
  vector<dice> all_rolls() {
    vector<dice> ret;
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        ret.push_back(*this);
    return ret;
  }
  bool equivalent_to(const dice& di) {
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        if (*this == di) return true;
    return false;
  }
private:
  void roll(FACE a, FACE b, FACE c, FACE d) {
    int tmp = id[a];
    id[a] = id[b]; id[b] = id[c];
    id[c] = id[d]; id[d] = tmp;
  }
  T var[6];
  int id[6];
};

bool operator < (const dice<int> &a, const dice<int> &b) {
  if (a[TOP]!=b[TOP]) return a[TOP] < b[TOP];
  if (a[FRONT]!=b[FRONT]) return a[FRONT] < b[FRONT];
  if (a[BACK]!=b[BACK]) return a[BACK] < b[BACK];
  if (a[BOTTOM]!=b[BOTTOM]) return a[BOTTOM] < b[BOTTOM];
  if (a[LEFT]!=b[LEFT]) return a[LEFT] < b[LEFT];
  return a[RIGHT] < b[RIGHT];;
}

struct P {
  int cost;
  int x;
  int y;
  dice<int> di;
  P(int cost,int x,int y,dice<int> di) : cost(cost),x(x),y(y),di(di) {}
};
bool operator<(const P &a, const P &b) {
  return a.cost>b.cost;
}

  

int main() {
  int h, w;
  while(cin>>h>>w,h) {
    int ba[w][h];
    REP(y,h)
      REP(x,w)
        cin >> ba[x][y];
    int sx,sy,gx,gy;
    cin>>sy>>sx>>gy>>gx;

    int arr[] = {1,2,4,3,5,6};
    dice<int> di(arr);

    priority_queue<P> Q;
    Q.push(P(0,sx,sy,di));
    map<dice<int>,bool> visited[w][h];
//    memset(visited,0,sizeof(visited));
    map<dice<int>,int> res[w][h];
    vector<dice<int> > vvv = di.all_rolls();
    REP(i,vvv.size()) {
      REP(x,w) REP(y,h) {
        res[x][y][vvv[i]] = INF;
      }
    }
    res[sx][sy][di] = 1;
    while(!Q.empty()) {
      P p =Q.top();
      Q.pop();
      int x=p.x,y=p.y,cost=p.cost;
      dice<int> nd = p.di;
      if (visited[x][y][nd]) {
//        printf("a %d,%d %d\n",x,y,cost);
        continue;
      }
      //     printf("%d,%d %d\n",x,y,cost);
      visited[x][y][nd] = 1;
      //cout << res[x][y][nd] << endl;
      const int dx[] = {0,1,0,-1};
      const int dy[] = {-1,0,1,0};
      REP(k,4) {
        int xx = x+dx[k];
        int yy = y+dy[k];
        if (xx<0||xx>=w||yy<0||yy>=h) continue;

        dice<int> tmp = nd;
        if (k == 0) { tmp.roll_x();tmp.roll_x();tmp.roll_x(); }
        else if (k == 1) tmp.roll_y();
        else if (k == 2) tmp.roll_x();
        else { tmp.roll_y();tmp.roll_y();tmp.roll_y(); }
        
        if (res[xx][yy][tmp] > cost + tmp[BOTTOM]*ba[xx][yy]) {
          res[xx][yy][tmp] = cost + tmp[BOTTOM]*ba[xx][yy];
          Q.push(P(res[xx][yy][tmp], xx,yy, tmp));
        }
      }
    }
    int rs = INF;
    REP(i,vvv.size())
      rs = min(rs, res[gx][gy][vvv[i]]);
    cout << rs << endl;
  }
}

Measured memory_bytes: 1208