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_max = 0



for i in range(n - 1):

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

    if d > d_max:

        d_max = d



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

if d > d_max:

    d_max = d



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_max = 0
for i in range(n - 1):
    d = a[i + 1] - a[i]
    if d > d_max:
        d_max = d
d = (k - a[-1]) + a[0]
if d > d_max:
    d_max = d
print((k - d_max))

-    d_max = max(d_max, d) +    if d > d_max: +        d_max = d -d_max = max(d_max, d) +if d > d_max: +    d_max = d