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

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



max_dist = 0

for i in range(n - 1):

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

max_dist = max(max_dist, A[0] + k - A[i + 1])



print((k - max_dist))

K, N, *A = list(map(int, open(0).read().split()))

A = [A[-1] - K] + A



max_gap = 0

for a1, a2 in zip(A, A[1:]):

    max_gap = max(max_gap, a2 - a1)

print((K - max_gap))

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

K, N, *A = list(map(int, open(0).read().split()))
A = [A[-1] - K] + A
max_gap = 0
for a1, a2 in zip(A, A[1:]):
    max_gap = max(max_gap, a2 - a1)
print((K - max_gap))

-k, n = list(map(int, input().split())) -A = list(map(int, input().split())) -max_dist = 0 -for i in range(n - 1): -    max_dist = max(max_dist, A[i + 1] - A[i]) -max_dist = max(max_dist, A[0] + k - A[i + 1]) -print((k - max_dist)) +K, N, *A = list(map(int, open(0).read().split())) +A = [A[-1] - K] + A +max_gap = 0 +for a1, a2 in zip(A, A[1:]): +    max_gap = max(max_gap, a2 - a1) +print((K - max_gap))