object Main extends App {
  val in = scala.io.Source.stdin.getLines.toIndexedSeq
  val h = in.head.split(' ').map(_.toInt)
  val L = h(0)
  val X = in.tail.map(_.toInt)
  //println(L, X)
  
  private def func(flag:Boolean):Long = { 
    var acc = 0L
    var cl = 0
    var cr = X.size - 1
    var pos = 0
    while(cl <= cr){
      val dl = if(pos < X(cl)) X(cl) - pos else X(cl) + L - pos
      val dr = if(pos < X(cr)) L - X(cr) + pos else pos - X(cr)
      //println(dl,dr)
      if(flag && acc==0 || dl > dr){
        //println("dl="+dl)
        acc += dl
        pos = X(cl)
        cl += 1
      }else{
        //println("dr="+dr)
        acc += dr
        pos = X(cr)
        cr -= 1
      }
    }
    acc
  }
  println(Math.max(func(true), func(false)))
  //println(func(false))
}
