program abc160c
  integer :: k, n, a(200001), diff(200000)
  read *, k, n, a(1:n)
  diff(1:n) = a(2:n+1) - a(1:n)
  diff(n) = a(1) + k - a(n)
  print *, sum(diff(1:n)) - maxval(diff(1:n))
end program abc160c
