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

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



a.append(a[0] + k)

m = 0

for i in range(n):

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

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

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

a.append(a[0] + k)

m = []

for i in range(n):

    m.append(a[i+1] - a[i])

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

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

-m = 0 +m = [] -    m = max(m, a[i + 1] - a[i]) -print((k - m)) +    m.append(a[i + 1] - a[i]) +print((k - max(m)))