p00223 Stray Twins_16144
Takayuki and Kazuyuki are good twins, but their behavior is exactly the opposite. For example, if Takayuki goes west, Kazuyuki goes east, and if Kazuyuki goes north, Takayuki goes south. Currently the two are in a department store and are in different locations. How can two people who move in the opposite direction meet as soon as possible?

A department store is represented by a grid consisting of W horizontal x H vertical squares, and two people can move one square from north, south, east, and west per unit time. However, you cannot move outside the grid or to a square with obstacles.

As shown, the position of the grid cells is represented by the coordinates (x, y).

<image>


Create a program that inputs the grid information and the initial positions of the two people and outputs the shortest time until the two people meet. If you can't meet, or if it takes more than 100 hours to meet, print NA. The grid information is given by the numbers in rows H and columns W, and the location information of the two people is given by the coordinates.

If either Takayuki-kun or Kazuyuki-kun is out of the range of the obstacle or grid after moving, you cannot move, so the one who is out of the range of the obstacle or grid is the original place. But if you don't, you can move without returning to the original place.

When two people meet, it means that they stay in the same square after moving. Even if two people pass each other, they do not meet.



Input

A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:


W H
tx ty
kx ky
d11 d21 ... dW1
d12 d22 ... dW2
::
d1H d2H ... dWH


The first line gives the department store sizes W, H (1 ≤ W, H ≤ 50). The second line gives Takayuki's initial position tx, ty, and the third line gives Kazuyuki's initial position kx, ky.

The H line that follows gives the department store information. di, j represents the type of square (i, j), 0 for movable squares and 1 for obstacles.

The number of datasets does not exceed 100.

Output

Outputs the shortest time on one line for each input dataset.

Example

Input

6 6
2 4
6 2
0 0 0 0 1 0
0 1 0 0 0 0
0 1 0 0 0 0
0 0 0 1 0 0
0 0 0 0 0 1
0 0 0 0 0 0
3 3
1 1
3 3
0 0 0
0 1 0
0 0 0
0 0


Output

3
NA

import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new aoj0223().doIt();
    }
    class aoj0223{
    	int mx[] = {0,1,0,-1};
    	int my[] = {1,0,-1,0};
    	boolean map[][] = new boolean[53][53];
    	class Par{
    		int x,y;
    		public Par(int x,int y){
    			this.x = x;
    			this.y = y;
    		}
    	}
    	ArrayList<Par> array = new ArrayList<Par>();
    	ArrayList<Par> array2 = new ArrayList<Par>();
    	TreeSet<String> ts = new TreeSet<String>();
    	int roop(int x,int y){
    		for(int i = 0;i < 101;i++){
    			int length = array.size();
//    			System.out.println(i);
    			for(int j = 0;j < length;j++){
    				Par p = array.remove(0);
    				Par p2 = array2.remove(0);
    				int sx = p.x;
    				int sy = p.y;
    				int ex = p2.x;
    				int ey = p2.y;
    				if(sx == ex && sy == ey)return i;
            		for(int k = 0;k < 4;k++){
            			int sx1 = sx;
            			int sy1 = sy;
            			int ex1 = ex;
            			int ey1 = ey;
            			if(sx + mx[k] >= 0 && sx + mx[k] < x
            					&& sy + my[k] >= 0 && sy + my[k] < y){
            				if(map[sy + my[k]][sx + mx[k]]){
            					sx1 = sx + mx[k];
            					sy1 = sy + my[k];
            				}
            			}
            			if(ex - mx[k] >= 0 && ex - mx[k] < x
            					&& ey - my[k] >= 0 && ey - my[k] < y){
            				if(map[ey - my[k]][ex - mx[k]]){
            					ex1 = ex - mx[k];
            					ey1 = ey - my[k];
            				}
            			}
            			String str = sx1+","+sy1+","+ex1+","+ey1;
            			if(ts.add(str)){
//            				System.out.println(str);
    						array.add(new Par(sx1,sy1));
    						array2.add(new Par(ex1,ey1));
    					}
            		}
    			}
    		}
    		return -1;
    	}
        void doIt() {
        	while(true){
        		int X = sc.nextInt();
        		int Y = sc.nextInt();
        		if(X+Y == 0)break;
        		array.add(new Par(sc.nextInt()-1,sc.nextInt()-1));
        		array2.add(new Par(sc.nextInt()-1,sc.nextInt()-1));
        		for(int i = 0;i < Y;i++){
        			for(int j = 0;j < X;j++){
        				map[i][j] = sc.nextInt() == 0 ? true:false ;
        			}
        		}
//        		for(int i = 0;i < Y;i++){
//        			for(int j = 0;j < X;j++){
//        				System.out.print(map[i][j]);
//        			}
//        			System.out.println();
//        		}
        		int num = roop(X,Y);
        		if(num == -1)System.out.println("NA");
        		else System.out.println(num);
        		array.clear();
        		array2.clear();
        		ts.clear();
        	}
    	}
    }
}