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

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

B = [A[i + 1] - A[i] for i in range(N - 1)]

B.append(A[0] + K - A[N - 1])

print((sum(B) - max(B)))

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

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

B = []

for i in range(1, n):

    B.append(A[i]-A[i-1])

B.append(k-sum(B))

print((k-max(B)))

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

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

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