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

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



a.append(a[0] + k)

m = 0

s = 0

for i in range(n):

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

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

print((s - 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 = 0
s = 0
for i in range(n):
    m = max(m, a[i + 1] - a[i])
    s += a[i + 1] - a[i]
print((s - 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))

-s = 0 -    s += a[i + 1] - a[i] -print((s - m)) +print((k - m))