Module Module1
    Sub main()

        Dim user2 As List(Of String) = New List(Of String)(Split(Console.ReadLine(), " "))
        Dim enkei As Long = user2(0)
        Dim houseMax As Long = user2(1)
        Dim user3 As List(Of String) = New List(Of String)(Split(Console.ReadLine(), " "))
        Dim houses As New List(Of Long)(Array.ConvertAll(user3.ToArray, Function(i As String) CLng(i)))
        Dim result As Long

        result = houses(0) - houses(houses.Count - 1) + enkei
        'Console.WriteLine(result)


        For i = 0 To houses.Count - 2
            result = Math.Max(result, houses(i + 1) - houses(i))
            'Console.WriteLine(">" & result)
        Next

        result = enkei - result

        Console.WriteLine(result)
  end sub
end module