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

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

max_dist = 0



for i in range(N):

  if i == N - 1:

    dist = A[0] + K - A[i]

  else:

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

  

  if dist > max_dist:

    max_dist = dist

    

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

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

diff = [abs(A[i-1] - A[i]) for i in range(1, N)]

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



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

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

-max_dist = 0 -for i in range(N): -    if i == N - 1: -        dist = A[0] + K - A[i] -    else: -        dist = A[i + 1] - A[i] -    if dist > max_dist: -        max_dist = dist -print((K - max_dist)) +diff = [abs(A[i - 1] - A[i]) for i in range(1, N)] +diff.append(abs(A[0] - A[N - 1] + K)) +print((K - max(diff)))