The Right-Turn Drivers' Club

No attempts yetTime limit1sMemory limit128 MB

Problem

We are given a rectangular city map made of n×mn \times m unit squares, where 1n1001 \le n \le 100 and 1m1001 \le m \le 100. The rows are numbered from 11 to nn from top to bottom, and the columns from 11 to mm from left to right. Every square is either free or blocked, and traffic is allowed only on free squares.

From a free square you may move to a free square adjacent to it (one that shares a side). You may never immediately turn back, that is, you may not return to the square you have just left (no U-turn). You may also never make a left turn: after each move you may only keep going straight or turn right, relative to your current direction of travel. The very first move out of the start square may point in any of the four directions, because there is no previous direction yet.

The length of a route is the number of squares it passes through, counting both endpoints; a square may be counted more than once if the route visits it more than once.

You are given two different squares AA and BB. Decide whether it is possible to drive from AA to BB without any left turn, and if it is, report the minimum possible length of such a route. If AA or BB is blocked, no route exists.

Input

The first line contains two integers nn and mm separated by a single space.

Each of the next nn lines contains a string of length mm made of the digits 00 and 11 that describes one row of the map: 00 marks a free square and 11 marks a blocked square.

The next line contains two integers, the row and the column of square AA. The following line contains, in the same format, the row and the column of square BB. Squares AA and BB are different. The input is always well-formed and you do not need to validate it.

Output

Print a single line.

If there is no route from AA to BB without a left turn, or if AA or BB is blocked, print the single word NIE (Polish for "no").

Otherwise print one integer: the minimum length of a route from AA to BB that makes no left turn, that is, the number of squares it passes through, counting both AA and BB.