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

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



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

for i in range(len(A)-1):

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

print((k-farthest))

k, n, *A = list(map(int, open(0).read().split()))

far = k + A[0] - A[-1]

for x, y in zip(A[1:], A):

    if far < x - y:

        far = x - y

print((k-far))
k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
farthest = (k - A[-1]) + A[0]
for i in range(len(A) - 1):
    farthest = max(farthest, A[i + 1] - A[i])
print((k - farthest))

k, n, *A = list(map(int, open(0).read().split()))
far = k + A[0] - A[-1]
for x, y in zip(A[1:], A):
    if far < x - y:
        far = x - y
print((k - far))

-k, n = list(map(int, input().split())) -A = list(map(int, input().split())) -farthest = (k - A[-1]) + A[0] -for i in range(len(A) - 1): -    farthest = max(farthest, A[i + 1] - A[i]) -print((k - farthest)) +k, n, *A = list(map(int, open(0).read().split())) +far = k + A[0] - A[-1] +for x, y in zip(A[1:], A): +    if far < x - y: +        far = x - y +print((k - far))