program tree_burning
  implicit none
  integer :: n, i, top, btm
  integer(8) :: l, x(-200000:400001), m, t
  logical :: nat
  read(*,*) l, n
  x = 0_8
  x(n+1) = l
  do i = 1, n
    read(*,*) x(i)
    x(i-n-1) = x(i)-l
    x(i+n+1) = x(i)+l
  end do
  m = 0_8
  do i = 1, n
    t = 0_8
    top = i
    btm = n+1
    nat = .false.
    do while (top.le.btm)
      if (nat) then
        t = t + x(top+n+1)-x(btm)
        top = top+1
      else
        t = t + x(top)-x(btm-n-1)
        btm = btm-1
      end if
      nat = .not.nat
    end do
    m = max(m,t)
  end do
  do i = n, 1, -1
    t = 0_8
    top = 0
    btm = i
    nat = .true.
    do while (top.le.btm)
      if (nat) then
        t = t + x(top+n+1)-x(btm)
        top = top+1
      else
        t = t + x(top)-x(btm-n-1)
        btm = btm-1
      end if
      nat = .not.nat
    end do
    m = max(m,t)
  end do
  write(*,'(i0)') m-l
end program tree_burning