
object Main extends App {

  import scala.io.StdIn._

  val Array(n, q) = readLine.trim.split(' ').map(_.toInt)
  var nums= readLine.trim.split(' ').map(_.toInt).map{value ⇒ new BiList(value, None, None)}.let{a ⇒
    for (i ← 1 until a.length){
      a(i - 1).next = Some(a(i))
      a(i).prev = Some(a(i - 1))
    }
    a
  }
  val holder = new ListHolder(nums.head, nums.last)
  nums = nums.sortBy(_.value)
  val queries = readLine.trim.split(' ').map(_.toInt - 1)
  for (query <- queries){
    holder.swapAt(nums(query))
  }
  println(
    holder.toList.map(_.toString).mkString(" ")
  )
  class ListHolder(var first: BiList, var last: BiList) {
    def swapAt(q: BiList): Unit = {
      (q.prev, q.next) match {
        case (Some(leftLast), Some(rightFirst)) ⇒
          q.next = Some(first)
          first.prev = Some(q)
          q.prev = Some(last)
          last.next = Some(q)
          first = rightFirst
          last = leftLast
          first.prev = None
          last.next = None
        case (None, Some(rightFirst)) ⇒
          q.prev = Some(last)
          last.next = Some(q)
          first = rightFirst
          last = q
          first.prev = None
          last.next = None
        case (Some(leftLast), None) ⇒
          q.next = Some(first)
          first.prev = Some(q)
          first = q
          last = leftLast
          first.prev = None
          last.next = None
        case (None, None) ⇒
      }

    }
    def toList: List[Int] = {
      var l = last
      var res: List[Int] = l.value::Nil
      while (first != l){
        l = l.prev.get
        res ::= l.value
      }
      res
    }
  }
  class BiList(val value: Int, var prev: Option[BiList], var next: Option[BiList]) {
    override def toString: String = s"BiList($value, ${prev.map(_.value)}, ${next.map(_.value)})"
  }

  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
