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

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



b = 0

for i in range(n):

    if i == 0:

        if a[0] + k - a[-1] > b:

            b = a[0] - a[-1] + k

    if a[i] - a[i-1] > b:

        b = a[i] - a[i-1]



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

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



longest = k - (a[-1] - a[0])



for i in range(n-1):

    if a[i+1] - a[i] > longest:

        longest = a[i+1] - a[i]



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

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

-b = 0 -for i in range(n): -    if i == 0: -        if a[0] + k - a[-1] > b: -            b = a[0] - a[-1] + k -    if a[i] - a[i - 1] > b: -        b = a[i] - a[i - 1] -print((k - b)) +longest = k - (a[-1] - a[0]) +for i in range(n - 1): +    if a[i + 1] - a[i] > longest: +        longest = a[i + 1] - a[i] +print((k - longest))