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

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

D = [0]*n

for i in range(n):

    if i != n-1:

        D[i] = A[i+1]-A[i]

    if i == n-1:

        D[i] = A[0]+k-A[i]



#print(D)

ans = k - max(D)

print(ans)

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

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

D = []

for i in range(n-1):

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

else:

    D.append(k-(A[n-1]-A[0]))

D.sort(reverse=True)

print((k-D[0]))

k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
D = [0] * n
for i in range(n):
    if i != n - 1:
        D[i] = A[i + 1] - A[i]
    if i == n - 1:
        D[i] = A[0] + k - A[i]
# print(D)
ans = k - max(D)
print(ans)

k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
D = []
for i in range(n - 1):
    D.append(A[i + 1] - A[i])
else:
    D.append(k - (A[n - 1] - A[0]))
D.sort(reverse=True)
print((k - D[0]))

-D = [0] * n -for i in range(n): -    if i != n - 1: -        D[i] = A[i + 1] - A[i] -    if i == n - 1: -        D[i] = A[0] + k - A[i] -# print(D) -ans = k - max(D) -print(ans) +D = [] +for i in range(n - 1): +    D.append(A[i + 1] - A[i]) +else: +    D.append(k - (A[n - 1] - A[0])) +D.sort(reverse=True) +print((k - D[0]))