#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
template <class T>
class dice {
public:
  dice() {
    id[TOP] = 0; id[FRONT] = 1; id[LEFT] = 2;
    id[RIGHT] = 3; id[BACK] = 4; id[BOTTOM] = 5;
  }
  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;
  }
    bool operator<(const dice<T>& b)const{
		const dice<T> &a = *this;
		if(a[TOP]==b[TOP]){
			if(a[FRONT]==b[FRONT]){
				return a[RIGHT]<b[RIGHT];
			}
			return a[FRONT]<b[FRONT];
		}
		return a[TOP]<b[TOP];
    }
private:
  void roll(FACE a, FACE b, FACE c, FACE d) {
    T tmp = id[a];
    id[a] = id[b]; id[b] = id[c];
    id[c] = id[d]; id[d] = tmp;
  }
  T var[6];
  int id[6];
};

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

const int MAX=INT_MAX/10;
typedef map<dice<int>,int> md;
typedef vector<md> vm;
typedef vector<vm> vvm;
int dx[]={-1,0,1,0},dy[]={0,-1,0,1};

int main(){
    int h,w;
    while(cin>>h>>w,h){
        vvi field(h,vi(w));
        REP(i,h){
			REP(j,w){
				cin>>field[i][j];
			}
        }
		pii start,goal;
		cin>>start.first>>start.second;
		cin>>goal.first>>goal.second;

        priority_queue<node> q;
		dice<int> start_die;
		start_die[TOP]=1;
		start_die[FRONT]=2;
		start_die[RIGHT]=3;
		start_die[BOTTOM]=6;
		start_die[BACK]=5;
		start_die[LEFT]=4;
		q.push(node(start.first,start.second,start_die,0));
		vector<dice<int> > all_rolls=start_die.all_rolls();
        vvm cost(h,vm(w,md()));
		REP(i,h){
			REP(j,w){
				REP(k,all_rolls.size()){
					cost[i][j][all_rolls[k]]=MAX;
				}
			}
		}
		cost[start.first][start.second][start_die]=0;
        while(!q.empty()){
            node cnode=q.top();q.pop();
            if(cost[cnode.y][cnode.x][cnode.di]<cnode.cost){
                continue;
            }
			REP(i,4){
				int x=cnode.x+dx[i];
				int y=cnode.y+dy[i];
				if(x>=0&&y>=0&&x<w&&y<h){
					dice<int> newdie(cnode.di);
					switch(i){
					case 0:
						REP(j,3)newdie.roll_y();
						break;
					case 1:
						REP(j,3)newdie.roll_x();
						break;
					case 2:
						newdie.roll_y();
						break;
					case 3:
						newdie.roll_x();
						break;
					}
					int newcost=cnode.cost+field[y][x]*newdie[BOTTOM];
					if(cost[y][x][newdie]>newcost){
						cost[y][x][newdie]=newcost;
						q.push(node(y,x,newdie,newcost));
					}
				}
            }
        }
		int ans=MAX;
		REP(i,all_rolls.size()){
			ans=min(ans,cost[goal.first][goal.second][all_rolls[i]]);
		}
		cout<<ans<<endl;
    }
}

Measured memory_bytes: 1356