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

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

M = 0

i = 0

while i<N-1:

    if M<(A[i+1]-A[i]):

        M=(A[i+1]-A[i])

    i+=1



print((min(K-M,A[N-1]-A[0])))
k,n = list(map(int,input().split()))

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

A.append(k+A[0])

M = 0

for i in range(n):

    if A[i+1] - A[i] > M:

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

print((k-M))
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
M = 0
i = 0
while i < N - 1:
    if M < (A[i + 1] - A[i]):
        M = A[i + 1] - A[i]
    i += 1
print((min(K - M, A[N - 1] - A[0])))

k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
A.append(k + A[0])
M = 0
for i in range(n):
    if A[i + 1] - A[i] > M:
        M = A[i + 1] - A[i]
print((k - M))

-K, N = list(map(int, input().split())) +k, n = list(map(int, input().split())) +A.append(k + A[0]) -i = 0 -while i < N - 1: -    if M < (A[i + 1] - A[i]): +for i in range(n): +    if A[i + 1] - A[i] > M: -    i += 1 -print((min(K - M, A[N - 1] - A[0]))) +print((k - M))