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

lst = [int(x) for x in input().split()]

a = lst[0]

m = 0

for i in range(N - 1):

    m = max(m, (lst[i + 1] - a) - (lst[i] - a))



print((K - max(m, K - (lst[-1] - a))))

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

lst = [int(x) for x in input().split()]



m = K - lst[-1] + lst[0]

for i in range(N - 1):

    m = max(m, lst[i + 1] - lst[i])

print((K - m))
K, N = list(map(int, input().split()))
lst = [int(x) for x in input().split()]
a = lst[0]
m = 0
for i in range(N - 1):
    m = max(m, (lst[i + 1] - a) - (lst[i] - a))
print((K - max(m, K - (lst[-1] - a))))

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

-a = lst[0] -m = 0 +m = K - lst[-1] + lst[0] -    m = max(m, (lst[i + 1] - a) - (lst[i] - a)) -print((K - max(m, K - (lst[-1] - a)))) +    m = max(m, lst[i + 1] - lst[i]) +print((K - m))