import scala.io.StdIn

object Main extends App {
  while(Reader.hasNext()) {
    println(Reader.next().count())
  }
}

object Reader extends Iterator[BraveForceStory] {
  private var nextVal = readOnce()

  override def hasNext() = {
    nextVal.nonEmpty
  }

  override def next() = {
    val retVal = nextVal.get
    nextVal = readOnce()
    retVal
  }

  private def readOnce(): Option[BraveForceStory] = {
    val first = createTuple(StdIn.readLine())
    if (first != (0, 0)) {
      Option(BraveForceStory(first._1,
        (1 to first._2).map(i => createTuple(StdIn.readLine())),
        createTuple(StdIn.readLine())
      ))
    } else {
      Option.empty
    }
  }

  def createTuple(line: String): (Int, Int) = {
    val splited = line.split("\\s").map(str => str.toInt)
    (splited(0), splited(1))
  }
}

case class BraveForceStory(step: Int, obstacles: Seq[(Int, Int)], startPos: (Int, Int)) extends Iterator[Int] {
  private var counter = 0
  private var restStep = step
  private var edge: Set[(Int, Int)] = Set(startPos)
  private var innerEdge: Set[(Int, Int)] = Set()

  def count() = {
    while (this.hasNext()) {
      this.next()
    }
    counter
  }

  override def hasNext() = {
    restStep >= 0
  }

  override def next() = {
    restStep = restStep - 1
    counter = counter + edge.size

    val nextEdge = edge.flatMap(neighbors).filter(neighbor => !(edge ++ innerEdge).contains(neighbor)).filter(neighbor => !obstacles.contains(neighbor))
    innerEdge = edge
    edge = nextEdge

    counter
  }

  private def neighbors(pos: (Int, Int)): Set[(Int, Int)] = {
    Set(
      (pos._1 + 1, pos._2 + 1),
      (pos._1 + 1, pos._2),
      (pos._1, pos._2 + 1),
      (pos._1, pos._2 - 1),
      (pos._1 - 1, pos._2),
      (pos._1 - 1, pos._2 - 1)
    )
  }
}