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

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



ans = A[N-1] - A[0]

for i in range(N):

    ans = min(ans, min(A[(i+N-1)%N] + K - A[i], A[i] + K - A[(i+1)%N]))



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

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



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

for i in range(N-1):

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



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

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

-ans = A[N - 1] - A[0] -for i in range(N): -    ans = min(ans, min(A[(i + N - 1) % N] + K - A[i], A[i] + K - A[(i + 1) % N])) -print(ans) +dist = [K - A[N - 1] + A[0]] +for i in range(N - 1): +    dist.append(A[i + 1] - A[i]) +print((K - max(dist)))