#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

using namespace std;

const int INF = 1 << 29;
typedef long long ll;
typedef pair<int,int> PI;

int maze[60][60];
int X, Y, tx, ty, kx, ky;

bool passed[50][50][50][50];

struct P
{
	int tx, ty;
	int kx, ky;
	int cost;

	P(int _tx, int _ty, int _kx, int _ky, int _cost) : tx(_tx), ty(_ty), kx(_kx), ky(_ky), cost(_cost) {};
};

bool check(int x, int y){
	return x < 0 || x >= X || y < 0 || y >= Y || maze[y][x];
}

int main(void){
	while(cin >> X >> Y, X|Y){
		int ans = -1;
		cin >> tx >> ty >> kx >> ky;
		tx--, ty--, kx--, ky--;

		for(int i=0; i<Y; ++i){
			for(int j=0; j<X; ++j){
				cin >> maze[i][j];
			}
		}

		queue<P> que;
		memset(passed, 0, sizeof(passed));


/*		for(int i=0; i<Y; ++i){
			for(int j=0; j<X; ++j){
				for(int k=0; k<Y; ++k){
					for(int l=0; l<X; ++l){
						d[i][j][k][l] = INF;
					}
				}
			}
		}
*/
		for(que.push(P(tx, ty, kx, ky, 0)); !que.empty(); que.pop()){
			P p = que.front();

			if(p.cost >= 100) break;
			if(p.tx == p.kx && p.ty == p.ky){
				ans = p.cost;
				break;
			}

			for(int dx=-1; dx<=1; dx++){
				for(int dy=-1; dy<=1; dy++){
					if(abs(dx-dy) != 1) continue;
					int ntx = p.tx + dx, nty = p.ty + dy;
					int nkx = p.kx - dx, nky = p.ky - dy;

					if(check(ntx, nty)) ntx = p.tx, nty = p.ty;
					if(check(nkx, nky)) nkx = p.kx, nky = p.ky;
					if(passed[ntx][nty][nkx][nky]) continue;

					passed[ntx][nty][nkx][nky] = true;
					que.push(P(ntx, nty, nkx, nky, p.cost + 1));
				}
			}
		}

		if(ans == -1){
			cout << "NA" << endl;
		} else {
			cout << ans << endl;
		}
	}

	return 0;
}