#P2022G. Burning
Burning
Burning
Time limit: 1 seconds
Memory limit: 512 megabytes
Problem Statement
The ACM laboratory can be represented by a grid diagram. Bing's seat is at cell and Frank's seat is at cell .
In this grid, each cell has an ignition point . If one cell is on fire, the flame will continuously try to spread to its upper , lower , left and right 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 .
The second line contains four integers denoting Bing's seat and Frank's seat .
In the following lines, each line containing integers. The -th integer in the -th line is denoting the ignition point of cell .
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