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

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

d = [0] * n

d_max = 0



for i in range(n - 1):

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

    d_max = max(d_max, d[i])



d[-1] = (k - a[-1]) + a[0]

d_max = max(d_max, d[-1])



print((k - d_max))

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

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

d_max = 0



for i in range(n - 1):

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

    d_max = max(d_max, d)



d = (k - a[-1]) + a[0]

d_max = max(d_max, d)



print((k - d_max))

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

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

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