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

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

a.append(k + a[0])

dist = 0

for i in range(n):

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

print((k - dist))

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

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

a.append(k + a[0])

dist = [0]*n

for i in range(n):

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

print((k - max(dist)))

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

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

-dist = 0 +dist = [0] * n -    dist = max(dist, a[i + 1] - a[i]) -print((k - dist)) +    dist[i] = a[i + 1] - a[i] +print((k - max(dist)))