object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val Array(h, w, n) = readLine.trim.split(' ').map(_.toInt)
  val floor = Array.tabulate(h){_ ⇒
    val line = readLine.trim.split(' ').map(_.toInt)
    (for (i ← 0 until line.length by 2) yield {
      (line(i), line(i + 1))
    }).toArray
  }
  val memo = RichArray(Array.tabulate(h){_ ⇒ Array.tabulate(w){_ ⇒ false}})
  val person = Array.tabulate(n){_ ⇒
    val Array(r, c) = readLine.trim.split(' ').map(_.toInt)
    (r, c)
  }
  var isCollide: Option[Int] = None
  for (count ← 1 to h * w if isCollide.isEmpty){
    for (i ← person.indices){
      person(i) = floor(person(i))
      if (memo(person(i))) isCollide = Some(count)
      memo(person(i)) = true
    }
    for (p ← person){
      memo(p) = false
    }
  }
  println(
    isCollide match {
      case Some(c) ⇒ c
      case None ⇒ -1
    }
  )


  implicit class RichArray[T](val array: Array[Array[T]]) {
    def apply(coordinate: (Int, Int)): T = array(coordinate._1)(coordinate._2)
    def update(coordinate: (Int, Int), value: T) = array(coordinate._1)(coordinate._2) = value
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
