k, n = list(map(int, input().split()))

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

big = 0



for i in range(n - 1):

    big = max(big, abs(A[i + 1] - A[i]))

b = (k - A[-1]) + A[0]

big = max(big, b)

print((k - big))







k, n = list(map(int, input().split()))

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



kyori = []

for i in range(n - 1):

    kyori.append(abs(A[i] - A[i + 1]))



kyori.append(A[0] + (k-A[-1]))



ans = k - max(kyori)

print(ans)
k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
big = 0
for i in range(n - 1):
    big = max(big, abs(A[i + 1] - A[i]))
b = (k - A[-1]) + A[0]
big = max(big, b)
print((k - big))

k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
kyori = []
for i in range(n - 1):
    kyori.append(abs(A[i] - A[i + 1]))
kyori.append(A[0] + (k - A[-1]))
ans = k - max(kyori)
print(ans)

-big = 0 +kyori = [] -    big = max(big, abs(A[i + 1] - A[i])) -b = (k - A[-1]) + A[0] -big = max(big, b) -print((k - big)) +    kyori.append(abs(A[i] - A[i + 1])) +kyori.append(A[0] + (k - A[-1])) +ans = k - max(kyori) +print(ans)