#P2022G. Burning

    ID: 118 Type: Default 1000ms 256MiB Tried: 11 Accepted: 7 Difficulty: 8 Uploaded By: Tags>福建师范大学第19届程序设计竞赛

Burning

Burning

Time limit: 1 seconds

Memory limit: 512 megabytes

Problem Statement

The ACM laboratory can be represented by a nmn * m grid diagram. Bing's seat is at cell (a,b)(a,b) and Frank's seat is at cell (c,d)(c,d).

In this grid, each cell (x,y)(x,y) has an ignition point ax,ya_{x,y}. If one cell (x,y)(x,y) is on fire, the flame will continuously try to spread to its upper (x,y+1)(x,y+1), lower (x,y1)(x,y-1), left (x1,y)(x-1,y) and right (x+1,y)(x+1,y) cells. The adjacent cell will catch fire immediately if the temperature of the flame is greater or equal to its ignition point and the temperature of this cell will be the same as where the fire came from.

It may be that the weather in Fuzhou is too hot or Bing is too hot, Bing's seat is on fire automatically. What's worse, the temperature of the flame increases by one degree per second and the fire could not be put out for some reason.

Bing wants to know what the temperature is when the fire reaches the Frank's seat so he can calculate how much time is left before Frank realizes and starts to kill him. Note that the initial temperature of the fire is the ignition point of Bing's seat.

Input

The first line contains two integers n,m(1n,m500)n,m(1 \leq n,m \leq 500).

The second line contains four integers a,b,c,d(1a,cn,1b,dm)a,b,c,d(1 \leq a,c \leq n,1 \leq b,d \leq m) denoting Bing's seat (a,b)(a,b) and Frank's seat (c,d)(c,d).

In the following nn lines, each line containing mm integers. The jj-th integer in the ii-th line is ai,j(1ai,j109)a_{i,j}(1 \leq a_{i,j} \leq 10^9) denoting the ignition point of cell (i,j)(i,j).

Output

Print a single integer, denoting the answer to the question.

2 2 
1 1 2 2
6 10
3 3
6
3 4
2 2 2 3
1 2 5 6
4 6 9 5
3 8 2 4
9