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

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

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

for i in range(1,N):

    cnt = max(cnt,A[i]-A[i-1])

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

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

tmin = 2*K

for i in range(1,N):

    tmin = min(tmin,K-(A[i]-A[i-1]))

tmin = min(tmin,A[N-1]-A[0])

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

K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
tmin = 2 * K
for i in range(1, N):
    tmin = min(tmin, K - (A[i] - A[i - 1]))
tmin = min(tmin, A[N - 1] - A[0])
print(tmin)

-cnt = K + A[0] - A[N - 1] +tmin = 2 * K -    cnt = max(cnt, A[i] - A[i - 1]) -print((K - cnt)) +    tmin = min(tmin, K - (A[i] - A[i - 1])) +tmin = min(tmin, A[N - 1] - A[0]) +print(tmin)