Imports System.Text
Imports System.String
Imports System
Imports System.Math

Module Module1

    Sub Main()
        Dim ans As String = ""
        Dim input As String() = Console.ReadLine.Split(" "c)

        Dim lakelength As Integer = CInt(input(0))
        Dim valuelength = CInt(input(1))

        Dim lakehouses(valuelength - 1) As Integer
        Dim tempstr As String() = Console.ReadLine.Split(" "c)

        Dim i As Integer = 0
        For Each str As String In tempstr
            lakehouses(i) = CInt(str)
            i = i + 1
        Next


        Dim house As Integer = lakehouses(0)
        Dim maxdistance As Integer = 0
        For Each tempint As Integer In lakehouses
            If tempint - house >= maxdistance Then
                maxdistance = tempint - house
            End If
            house = tempint
        Next

        If lakelength - lakehouses(lakehouses.Length - 1) + lakehouses(0) >= maxdistance Then
            maxdistance = lakelength - lakehouses(lakehouses.Length - 1) + lakehouses(0)
        End If

        Console.WriteLine(lakelength - maxdistance)
        Console.ReadKey()
    End Sub


End Module