object Main extends App {
    val tempList: Seq[Seq[String]] = {
      for (line <- io.Source.stdin.getLines()) yield {
        line.split(' ').toSeq
      }
    }.toSeq
    val X: Int = tempList(0)(0).toInt
    val N: Int = tempList(0)(1).toInt
    
    val numList: Seq[Int] = tempList(1).map(_.toInt)

    val minOfNumList: Int = numList.min
    val maxOfNumList: Int = numList.max
    
    //値がこの範囲外
    

    val rangeMinMax: Set[Int] = Range(minOfNumList, maxOfNumList).toList.toSet
    val diffRange: Set[Int] = rangeMinMax.diff(numList.toSet)

    val diffList: Seq[Int] = diffRange.toList
    val diffAbsList: Seq[Int] = diffList.map(x => (x-X).abs)
    val minIndex: Int = diffAbsList.indexOf(diffAbsList.min)
    val minOfDiffList: Int = diffList(minIndex)


    println(minOfDiffList)
}