#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ST first
#define ND second
#define PB push_back

int main() {
    ios_base::sync_with_stdio(0);
    int w, h;
    int sx, sy, ex, ey;
    scanf("%d%d", &w, &h);
    w/=2; h/=2;
    scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
    vector<vector<int>> heights (h, vector<int>(w));
    for(int i=0; i < h; i++) {
        for(int j=0; j < w; j++) {
            scanf("%d", &heights[i][j]);
        }
    }
    if(sx == ex) {
        int x = sx/2;
        int res = 0;
        if(sy > ey) {
            swap(sy, ey);
        }
        res = ey-sy;
        for(int y=sy/2; y < ey/2; y++) {
            res+=abs(heights[y][x]-heights[y+1][x]);
        }
        printf("%d\n", res);
        return 0;
    } else if(sy == ey) {
        int y = sy/2;
        int res = 0;
        if(sx > ex) {
            swap(sx, ex);
        }
        res = ex-sx;
        for(int x=sx/2; x < ex/2; x++) {
            res+=abs(heights[y][x]-heights[y][x+1]);
        }
        printf("%d\n", res);
        return 0;
    }
    
    if(sy > ey) {
        swap(sx, ex);
        swap(sy, ey);
    }
    pll vec = {ex-sx, ey-sy};
    if(vec.ST < 0) {
        vec.ST*=-1;
        sx = 2*w-sx;
        ex = 2*w-ex;
        for(int i=0; i < h; i++) {
            reverse(heights[i].begin(), heights[i].end());
        }
    }
    int bx = sx/2, by = sy/2;
    double res = sqrt(vec.ST*vec.ST + vec.ND*vec.ND);
    int sum = 0;
    while(bx != ex/2 || by != ey/2) {
        pll cur = {2*bx+2-sx, 2*by+2-sy};
        ll det = cur.ST*vec.ND - cur.ND*vec.ST;
        if(det == 0) {
            int maxh = max(heights[by][bx], heights[by+1][bx+1]);
            int borderh = min(heights[by+1][bx], heights[by][bx+1]);
            if(borderh > maxh) {
                sum+= abs(borderh-heights[by][bx]);
                sum+= abs(borderh-heights[by+1][bx+1]);
            } else {
                sum+= abs(heights[by][bx]-heights[by+1][bx+1]);
            }
            bx++; by++;
        } else if(det > 0) {
            sum+= abs(heights[by+1][bx]-heights[by][bx]);
            by++;
        } else {
            sum+= abs(heights[by][bx+1]-heights[by][bx]);
            bx++;
        }
    }
    res+=sum;
    printf("%.10lf\n", res);
}