program lake
  implicit none

  integer :: k, n, i
  integer, allocatable :: a(:), b(:)

  read *, k, n
  allocate(a(n), b(n))
  read *, a

  do i = 1, n-1
     b(i) = a(i+1) - a(i)
  end do
  b(n) = k - a(n) + a(1)
  print *, b

  print *, k - maxval(b)

  deallocate(a, b)

  stop
end program lake
