### constant

MAX_INT = (1 << 31) - 1
MAX_D = 100

DIRCS = [[1, 0], [0, -1], [-1, 0], [0, 1]]

### main

while true
  w, h = gets.strip.split(' ').map{|s| s.to_i}
  break if w == 0 && h == 0

  tx, ty = gets.strip.split(' ').map{|s| s.to_i - 1}
  kx, ky = gets.strip.split(' ').map{|s| s.to_i - 1}

  brd = w.times.map{gets.strip.split(' ').map{|s| s == '0'}}

  dists = w.times.map{h.times.map{w.times.map{h.times.map{MAX_INT}}}}
  visit = w.times.map{h.times.map{w.times.map{h.times.map{false}}}}
  q = []

  dists[tx][ty][kx][ky] = dists[kx][ky][tx][ty] = 0
  visit[tx][ty][kx][ky] = visit[kx][ky][tx][ty] = true
  q << [tx, ty, kx, ky]

  while ! q.empty?
    x0, y0, x1, y1 = q.shift

    break if x0 == x1 && y0 == y1
    next if dists[x0][y0][x1][y1] >= MAX_D

    ndist = dists[x0][y0][x1][y1] + 1

    for k0 in (0..3)
      moved = false
      nx0 = x0 + DIRCS[k0][0]
      ny0 = y0 + DIRCS[k0][1]
      if nx0 >= 0 && nx0 < w && ny0 >= 0 && ny0 < h && brd[ny0][nx0]
        moved = true
      else
        nx0 = x0
        ny0 = y0
      end

      k1 = k0 ^ 2
      nx1 = x1 + DIRCS[k1][0]
      ny1 = y1 + DIRCS[k1][1]
      if nx1 >= 0 && nx1 < w && ny1 >= 0 && ny1 < h && brd[ny1][nx1]
        moved = true
      else
        nx1 = x1
        ny1 = y1
      end

      if moved && dists[nx0][ny0][nx1][ny1] > ndist
        dists[nx0][ny0][nx1][ny1] = dists[nx1][ny1][nx0][ny0] = ndist
        if ! visit[nx0][ny0][nx1][ny1]
          visit[nx0][ny0][nx1][ny1] = visit[nx1][ny1][nx0][ny0] = true
          q << [nx0, ny0, nx1, ny1]
        end
      end
    end
  end

  min_dist = MAX_INT
  for y in (0...h)
    for x in (0...w)
      if min_dist > dists[x][y][x][y]
        min_dist = dists[x][y][x][y]
      end
    end
  end

  if min_dist < MAX_D
    puts min_dist
  else
    puts 'NA'
  end
end