# -*- coding: utf-8 -*-

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

a = [int(i) for i in input().split()]

a.append(k + a[0])

l = 0

for i in range(n):

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

ans = k - l

print(ans)

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))

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

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))

-# -*- coding: utf-8 -*- -a = [int(i) for i in input().split()] +a = list(map(int, input().split())) -l = 0 +dist = 0 -    l = max(l, a[i + 1] - a[i]) -ans = k - l -print(ans) +    dist = max(dist, a[i + 1] - a[i]) +print((k - dist))