

K, N = list(map(int, input().split()))

A = list(map(int, input().split()))

lst = []

for i in range(1, N-1):

    diff_1 = abs(A[i + 1] - A[i])

    lst.append(diff_1)

    diff_2 = abs(A[i] - A[i - 1])

    lst.append(diff_2)



lst.append

lst.append(K + A[0] - A[N-1])

print((K - max(lst)))


K, N = list(map(int, input().split()))

A = list(map(int, input().split()))

lst = []

for i in range(1, N-1):

    diff_1 = abs(A[i + 1] - A[i])

    lst.append(diff_1)



lst.append(K + A[0] - A[N-1])

print((K - max(lst)))
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
lst = []
for i in range(1, N - 1):
    diff_1 = abs(A[i + 1] - A[i])
    lst.append(diff_1)
    diff_2 = abs(A[i] - A[i - 1])
    lst.append(diff_2)
lst.append
lst.append(K + A[0] - A[N - 1])
print((K - max(lst)))

K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
lst = []
for i in range(1, N - 1):
    diff_1 = abs(A[i + 1] - A[i])
    lst.append(diff_1)
lst.append(K + A[0] - A[N - 1])
print((K - max(lst)))

-    diff_2 = abs(A[i] - A[i - 1]) -    lst.append(diff_2) -lst.append