import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

class Dice {
    int F[6];
    this(int[] F) { this.F = F.dup; }
    Dice dup() { return new Dice(F); }
    override bool opEquals(Object o) { 
        auto d = cast(Dice)o;
        return F == d.F;
    }
    void roll(int d) {
        const R = [
            [1, 2, 4, 3], /* 0 - 5軸 */
            [0, 2, 5, 3], /* 1 - 4軸 */
            [0, 1, 5, 4]  /* 2 - 3軸 */
        ];
        auto p = F[ R[d][0] ];
        foreach (i; 0 .. 3) {
            F[ R[d][i] ] = F[ R[d][(i + 1) % 4] ];
        }
        F[ R[d][3] ] = p;
    }
    void roll(int d, int n) {
        foreach (_; 0 .. n) roll(d);
    }
    override size_t toHash() const {
        size_t ret = 0;
        foreach (i; 0 .. 6) {
            ret = ret * 10 + F[i];
        }
        return ret;
    }
    override int opCmp(Object o ) const {
        auto d = cast(Dice)o;
        return cast(int)toHash() - cast(int)o.toHash();
    }
    override string toString() const {
        return "(" ~ F[].map!(to!string).join(" ") ~ ")";
    }
    static Dice[] allStates(Dice d) {
        Dice[] ret;
        foreach (i; 0 .. 6) {
            d.roll(i % 2);
            foreach (j; 0 .. 4) {
                d.roll(2);
                ret ~= d.dup;
            }
        }
        return ret;
    }
}

int H, W;
int[][] F;
int sx, sy, gx, gy;
bool input() {
    scanf("%d %d\n", &H, &W);
    if (H == 0 && W == 0) return false;
    F = new int[][](H, W);
    foreach (i; 0 .. H) foreach (j; 0 .. W) scanf("%d", &F[i][j]);
    scanf("%d %d %d %d", &sy, &sx, &gy, &gx);
    return true;
}

const dy  = [-1, 0, 1, 0],
      dx  = [0, 1, 0, -1],
      dir = [ [2, 1], [1, 3], [2, 3], [1, 1] ];

struct State {
    int id, y, x, cost;
}

const INF = 1 << 28;

void solve() {
    auto init = new Dice([1, 2, 3, 4, 5, 6]);
    int[Dice] M; int id = 0;
    foreach (state; Dice.allStates(init)) {
        M[state] = id++;
    }
    auto N = new Dice[24];
    foreach (k, v; M) { N[v] = k; }

    BinaryHeap!(Array!State, "a.cost > b.cost") PQ;
    PQ.insert(State(M[init], sy, sx, 0));
    auto D = new int[][][](24, H, W);
    foreach (i; 0 .. 24) foreach (j; 0 .. H) D[i][j][] = INF;
    D[M[init]][sy][sx] = 0;
    while (!PQ.empty) {
        auto s = PQ.front; PQ.removeFront;
        foreach (i; 0 .. 4) {
            auto ny = s.y + dy[i],
                 nx = s.x + dx[i];
            if (ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
            auto nd = N[s.id].dup;
            nd.roll(dir[i][0], dir[i][1]);
            auto ncost = nd.F[5] * F[ny][nx] + s.cost;
            auto nid = M[nd];
            if (D[nid][ny][nx] > ncost) {
                D[nid][ny][nx] = ncost;
                PQ.insert(State(nid, ny, nx, ncost));
            }
        }
    }
    int ans = INF;
    foreach (i; 0 .. 24) {
        ans = min(ans, D[i][gy][gx]);
    }
    writeln(ans);
}

void main() {
    while (input) solve;
}