$dx = [0,1,0,-1,1,-1]
$dy = [1,0,-1,0,1,-1]
loop do
    t, n = gets.split.map(&:to_i)
    break if t == 0 && n == 0
    blocks = n.times.map{gets.split.map{|c| c.to_i}}
    sy, sx = gets.split.map(&:to_i)
    q = [[sy,sx]]
    visited = [[sy,sx]]
    t.times do
        q2 = []
        q.each do |sy,sx|
            for i in 0..5
                cy = sy + $dy[i]
                cx = sx + $dx[i]
                if !blocks.include?([cy,cx]) && !visited.include?([cy,cx])
                    q2.push([cy,cx])
                    visited.push([cy,cx])
                end
                break
            end
        end
        q = q2
    end
    puts visited.size
end