h,w,g[10][10],sx,sy,gx,gy;P[11][10][7][7],*a;Q[999][999],N[1000];E(p,x,y,u,s,e){p+=g[x][y]*(7-u);a=P[x][y][u]+s;p<*a?*a=p,Q[p][N[p]++]=x+y*10|u<<8|s<<16|e<<24:0;}main(x,y,p,t,u,s,e){for(;scanf("%d%d",&h,&w)*h;printf("%d\n",p)){for(y=0;y<h;y++)for(x=0;x<w;x++)scanf("%d",g[x]+y);scanf("%d%d%d%d",&sy,&sx,&gy,&gx);memset(P,1,2e4);memset(N,0,4e3);for(*Q[P[sx][sy][*N=1][2]=p=0]=0x3020100+sx+sy*10;;){if(N[p]){t=Q[p][--N[p]];x=t&255,y=x/10,x%=10;if(x==gx&&y==gy)break;u=t>>8&255;s=t>>16&255;e=t>>24&255;x>0&&E(p,x-1,y,e,s,7-u);x<w-1&&E(p,x+1,y,7-e,s,u);y>0&&E(p,x,y-1,s,7-u,e);y<h-1&&E(p,x,y+1,7-s,u,e);}else p++;}}}