13221 - BFS - Increasing   

Description

There is a  grid. Each cell  contains exactly one integer .

You are on  in the beginning and want to go to .

You could move to an adjacent cell if the integer of it is greater than or equal to the integer of the cell which you are on. An adjacent cell is a cell which shares a common side with the cell which you are on.

Find the minimum number of cells you need to pass by to reach . There may be no such a path for you to reach .

Input

The first line contains two positive integers  and   the size of the grid.

Then  lines folllow. The -th line contains  integers. The -th integer in the -th line  is the integer of the cell .

The next line contains two integers  and   the initial cell you are on.

The final line contains two integers  and   the cell you want to go.

Note that  and  must be different(i.e  or ).

 

It's guaranteed that:

  • The 1st testcase must be identical to the Sample #1 below
  • For the first 6 testcases:  and 

Output

Output the minimum cells you must pass by for you to reach . Output -1 instead if there is no such a path.

Remember to print a newline('\n') character at the end of the line.

 

Note: there are two sample below. "# Sample Input 1/2/3" and "# Sample Output 1/2/3" are not the part of input and output.

They are just for marking that the following content corresponds to which sample.

Sample Input  Download

Sample Output  Download

Tags




Discuss