program sample
    implicit none
    
    integer(8) :: a,b,c,i,j,m,n,k,a1,b1,c1
    integer(8), allocatable  ::x(:) 

    read(*,*) k,n
    allocate(x(n))
    read(*,*)x
    a=0
    do i=1,n-1
        b=x(i+1)-x(i)
        if (b>a)then
            a=b
        end if
    end do
    b=k-x(n)+x(1)
    if (b>a)then
        a=b
    end if
    write(*,*)k-a
    
    stop
end program sample
  

