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

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

l=[]

for i in range(n-1):

  l.append(A[i+1]-A[i])

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

print((sum(l)-max(l)))
k,n=list(map(int,input().split()))

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

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

[l.append(A[i+1]-A[i]) for i in range(n-1)]

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

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

-l = [] -for i in range(n - 1): -    l.append(A[i + 1] - A[i]) -l.append(k - A[-1] + A[0]) -print((sum(l) - max(l))) +l = [k - A[-1] + A[0]] +[l.append(A[i + 1] - A[i]) for i in range(n - 1)] +print((k - max(l)))