module C
  sub Main(byval args() as string)
    dim arr() as string = split(console.readline())
    dim k,n as long
    k = long.parse(arr(0))
    n = long.parse(arr(1))
    arr = split(console.readline())
    dim a_i(n) as long
    dim i as integer
    for i=0 to n-1
      a_i(i) = arr(i)
    next
    dim sa as long = 0
    for i=0 to n-2
      sa = if(sa<a_i(i+1)-a_i(i),a_i(i+1)-a_i(i),sa)
    next
    sa = if(sa<k-a_i(n-1)+a_i(0),k-a_i(n-1)+a_i(0),sa)
    console.writeline(k-sa)
  end sub
end module