
import std.stdio;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.range;
import std.typecons;

alias Tuple!(int, "x", int, "y") Point;
alias Tuple!(Point, "start", Point, "goal", int, "counter") State;

const auto directions = [[1, 0], [-1, 0], [0, 1], [0, -1]];

int[] read_nums() {return readln.chomp.split(" ").map!(to!(int)).array;}

void main() {
  while(true) {
    int[] data = read_nums;
    int width = data[0];
    int height = data[1];
    if (width == 0 && height == 0) break;
    data = read_nums;
    Point start = Point(data[0], data[1]);
    data = read_nums;
    Point goal = Point(data[0], data[1]);
    int[][] table;
    State[] queue;
    int ans = -1;
    table ~= repeat(-1).take(width + 2).array;
    foreach(i; 0..height) {
      table ~= [-1] ~ read_nums ~ [-1];
    }
    table ~= repeat(-1).take(width + 2).array;
    queue ~= State(start, goal, 0);
    while(!queue.empty) {
      State state = queue.front;
      // writeln(state.goal," ",state.start," ",state.counter, "    ", table);
      queue.popFront;
      if (state.start == state.goal) {
        ans = state.counter;
        break;
      }
      for(uint i = 0; i < directions.length; i++) {
        Point s = Point(state.start.x + directions[i][0],
                        state.start.y + directions[i][1]);
        Point g = Point(state.goal.x   - directions[i][0],
                        state.goal.y   - directions[i][1]);
        if (table[s.y][s.x] == 1 || table[s.y][s.x] == -1) continue;
        if (table[g.y][g.x] == 1 || table[g.y][g.x] == -1) g = state.goal;
        queue ~= State(s, g, state.counter + 1);
        table[s.y][s.x] = -1;
      }
    }
    writeln((ans == -1 || ans >= 100) ? "NA" : ans.to!(string));
  }
}