require 'set'
def bfs(start_node)
    return 0 if start_node.is_goal?
    reached = Set[start_node]
    dist = 1
    queue = [start_node]
    until queue.empty?
        next_queue = Set.new
        until queue.empty?
            node = queue.shift
            node.next_nodes.each do |next_node|
                return dist if next_node.is_goal?
                next if reached.include?(next_node)
                reached << next_node
                next_queue << next_node
            end
        end
        dist += 1
        queue = next_queue.to_a
    end
    return nil
end

class Array
    def is_goal?
        self[0] == self[2] && self[1] == self[3]
    end

    def next_nodes
        a = []
        [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |dx, dy|
            x1, y1 = self[0..1]
            if $field[y1+dy][x1+dx] == 0
                x1 += dx
                y1 += dy
            end
            x2, y2 = self[2..3]
            if $field[y2-dy][x2-dx] == 0
                x2 -= dx
                y2 -= dy
            end
            a << [x1, y1, x2, y2]
        end
        return a
    end
end

loop do
    w, h = gets.split.map(&:to_i)
    break if w == 0
    x1, y1 = gets.split.map(&:to_i)
    x2, y2 = gets.split.map(&:to_i)

    $field = (1..h).map { gets.split.map(&:to_i) }
    $field = [Array.new(w, 1)] + $field + [Array.new(w, 1)]
    $field.map! {|r| [1] + r + [1]}

    puts bfs([x1, y1, x2, y2]) || 'NA'
end

