
object Main extends App {

  import scala.io.StdIn._
  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val bestInterest = Array.tabulate(1001){ _ ⇒ Int.MaxValue}
  for (i ← 0 until n) {
    val cost = readLine.trim.toInt
    if (bestInterest(cost) > i) bestInterest(cost) = i + 1
  }
  for (i ← 1 to 1000) {
    if (bestInterest(i - 1) < bestInterest(i)) bestInterest(i) = bestInterest(i - 1)
  }
  val compe = Array.tabulate(n + 1){_ ⇒ 0}
    for (_ ← 0 until m) {
      compe(bestInterest(readLine.trim.toInt)) += 1
    }
  println(
    compe.indexOf(compe.max)
  )

}

