import scala.io.StdIn
import scala.collection.mutable.{Set => MutableSet}

object Main extends App {
  Reader.foreach(story =>
    println(story.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(turn: Int, obstacles: Seq[(Int, Int)], startPos: (Int, Int)) {

  def next(edge: Set[(Int, Int)], trace: Set[(Int, Int)], restStep: Int): Set[(Int, Int)] =
    if (restStep == 0) {
      edge ++ trace
    } else {
      next(
        edge.flatMap(neighbors).filter(neighbor => !(edge ++ trace).contains(neighbor)).filter(neighbor => !obstacles.contains(neighbor)),
        edge ++ trace,
        restStep - 1
      )
    }


  def count(): Int = {
    next(Set(startPos), Set(), turn).size
  }

  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)
    )
  }
}