K, N = list(map(int, input().split()))

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



result = A[0] - A[N - 1] + K

for i in range(N - 1):

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

print((K - result))

K, N = list(map(int, input().split()))

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

A.append(A[0]+K)

maxD = 0

for n in range(N):

  maxD = max(maxD, A[n+1] - A[n])

print((K-maxD))
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
result = A[0] - A[N - 1] + K
for i in range(N - 1):
    result = max(result, A[i + 1] - A[i])
print((K - result))

K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
A.append(A[0] + K)
maxD = 0
for n in range(N):
    maxD = max(maxD, A[n + 1] - A[n])
print((K - maxD))

-result = A[0] - A[N - 1] + K -for i in range(N - 1): -    result = max(result, A[i + 1] - A[i]) -print((K - result)) +A.append(A[0] + K) +maxD = 0 +for n in range(N): +    maxD = max(maxD, A[n + 1] - A[n]) +print((K - maxD))