#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;


class Dice {
public:
  int f[6];
  int x, y, cost;
  Dice() {
    f[0] = 1;
    f[1] = 2;
    f[2] = 3;
    f[3] = 6;
    f[4] = 5;
    f[5] = 4;
  }
  bool operator <(const Dice &d) const {
    if(x != d.x) return x < d.x;
    if(y != d.y) return y < d.y;
    for(int i = 0; i < 3; ++i) {
      if(f[i] != d.f[i]) return f[i] < d.f[i];
    }
    return false;
  }

  void rotate(int dx, int dy) {
    int tmp;
    tmp = f[0];
    if(dx == -1) {
      f[0] = f[2];
      f[2] = f[3];
      f[3] = f[5];
      f[5] = tmp;
    } else if(dx == 1) {
      f[0] = f[5];
      f[5] = f[3];
      f[3] = f[2];
      f[2] = tmp;
    }
    x += dx;

    tmp = f[0];
    if(dy == -1) {
      f[0] = f[1];
      f[1] = f[3];
      f[3] = f[4];
      f[4] = tmp;
    } else if(dy == 1) {
      f[0] = f[4];
      f[4] = f[3];
      f[3] = f[1];
      f[1] = tmp;
    }
    y += dy;
  }
};

class Dice2 {
public:
  Dice d;
  int cost;
  Dice2(Dice d, int cost) : d(d), cost(cost) {}
  bool operator <(const Dice2 &d2) const {
    return cost > d2.cost;
  }
};

int h, w;
int M[10][10];
int sx, sy;
int gx, gy;

void solve() {
  const int dx[4] = {1,0,-1,0};
  const int dy[4] = {0,1,0,-1};
  Dice d;
  d.x = sx;
  d.y = sy;
  d.cost = 0;
  priority_queue<Dice2> que;
  que.push(Dice2(d,0));
  set<Dice> vis;
  vis.insert(d);
  while(!que.empty()) {
    const Dice2 d2 = que.top(); que.pop();
    if(d2.d.x == gx && d2.d.y == gy) {
      cout << d2.cost << endl;
      return;
    }

    for(int i = 0; i < 4; ++i) {
      d = d2.d;
      int nx = d.x + dx[i];
      int ny = d.y + dy[i];
      if(nx < 0 || nx >= w) continue;
      if(ny < 0 || ny >= h) continue;
      d.rotate(dx[i], dy[i]);
      if(vis.find(d) != vis.end()) continue;
      vis.insert(d);
      que.push(Dice2(d, d2.cost + d.f[3]*M[ny][nx]));
    }
  }
}

int main() {
  while((cin >> h >> w) && (h || w)) {
    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
	cin >> M[i][j];
      }
    }
    cin >> sy >> sx;
    cin >> gy >> gx;
    solve();
  }
}