#include <iostream>
#include <queue>
#include <utility>
#include <set>
#include <vector>
using namespace std;

int main(void) {
	int X, Y;

	while(cin >> X >> Y, X | Y) {
		pair<int,int> t, k;
		vector<vector<int> > depart;
		set<pair<pair<int,int>,pair<int,int> > > moved;
		queue<pair<pair<pair<int,int>, pair<int,int> >, int> > q;
		int ans = -1;

		cin >> t.second >> t.first; t.first--; t.second--;
		cin >> k.second >> k.first; k.first--; k.second--;

		for(int i = 0; i < Y; i++) {
			vector<int> v;
			for(int j = 0; j < X; j++) {
				int tmp;
				cin >> tmp;
				v.push_back(tmp);
			}
			depart.push_back(v);
		}

		moved.insert(make_pair(t, k));
		q.push(make_pair(make_pair(t,k), 0));

		for(int i = 0;; i++) {
			pair<pair<int,int>, pair<int, int> > p;
			pair<int, int> next_t, next_k;
			int n;

			if(q.empty()) {
				break;
			}

			p = q.front().first; n = q.front().second; q.pop();
			if(p.first == p.second) {
				ans = n;
				break;
			}
			if(n > 100)
				break;

			next_t.first = p.first.first; next_t.second = p.first.second;
			next_k.first = p.second.first; next_k.second = p.second.second;
			if(p.first.first + 1 < Y && depart[p.first.first + 1][p.first.second] == 0) {
				next_t.first = p.first.first + 1;
				next_t.second = p.first.second;
			}
			if(p.second.first - 1 >= 0 && depart[p.second.first - 1][p.second.second] == 0) {
				next_k.first = p.second.first - 1;
				next_k.second = p.second.second;
			}
			if(moved.insert(make_pair(next_t, next_k)).second) {
				q.push(make_pair(make_pair(next_t, next_k),n + 1));
			}

			next_t.first = p.first.first; next_t.second = p.first.second;
			next_k.first = p.second.first; next_k.second = p.second.second;
			if(p.first.first - 1 >= 0 && depart[p.first.first - 1][p.first.second] == 0) {
				next_t.first = p.first.first - 1;
				next_t.second = p.first.second;
			}
			if(p.second.first + 1 < Y && depart[p.second.first + 1][p.second.second] == 0) {
				next_k.first = p.second.first + 1;
				next_k.second = p.second.second;
			}
			if(moved.insert(make_pair(next_t, next_k)).second) {
				q.push(make_pair(make_pair(next_t, next_k),n + 1));
			}

			next_t.first = p.first.first; next_t.second = p.first.second;
			next_k.first = p.second.first; next_k.second = p.second.second;
			if(p.first.second + 1 < X && depart[p.first.first][p.first.second + 1] == 0) {
				next_t.first = p.first.first;
				next_t.second  = p.first.second + 1;
			}
			if(p.second.second - 1 >= 0 && depart[p.second.first][p.second.second - 1] == 0) {
				next_k.first = p.second.first;
				next_k.second  = p.second.second - 1;
			}
			if(moved.insert(make_pair(next_t, next_k)).second) {
				q.push(make_pair(make_pair(next_t, next_k),n + 1));
			}

			next_t.first = p.first.first; next_t.second = p.first.second;
			next_k.first = p.second.first; next_k.second = p.second.second;
			if(p.first.second - 1 >= 0 && depart[p.first.first][p.first.second - 1] == 0) {
				next_t.first = p.first.first;
				next_t.second  = p.first.second - 1;
			}
			if(p.second.second + 1 < X && depart[p.second.first][p.second.second + 1] == 0) {
				next_k.first = p.second.first;
				next_k.second  = p.second.second + 1;
			}
			if(moved.insert(make_pair(next_t, next_k)).second) {
				q.push(make_pair(make_pair(next_t, next_k),n + 1));
			}
		}

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

Measured memory_bytes: 12052