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

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

a = a + [a[0]+k]

dif = [0]*n

for i in range(n):

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



dif.sort()

print((k-dif[-1]))
k,n = list(map(int, input().split()))

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

a = a + [a[0]+k]

dif = [0]*n

for i in range(n):

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

print((k-max(dif)))
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
a = a + [a[0] + k]
dif = [0] * n
for i in range(n):
    dif[i] += a[i + 1] - a[i]
dif.sort()
print((k - dif[-1]))

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

-dif.sort() -print((k - dif[-1])) +print((k - max(dif)))