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

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



diff = []



for i in range(n - 1):

    diff.append(a[i + 1] - a[i])

diff.append(k - a[-1] + a[0])



print((k - max(diff)))

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

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



a.append(k + a[0])

diff = [a1 - a0 for a0, a1 in zip(a, a[1:])]



print((k - max(diff)))

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

k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(k + a[0])
diff = [a1 - a0 for a0, a1 in zip(a, a[1:])]
print((k - max(diff)))

-diff = [] -for i in range(n - 1): -    diff.append(a[i + 1] - a[i]) -diff.append(k - a[-1] + a[0]) +a.append(k + a[0]) +diff = [a1 - a0 for a0, a1 in zip(a, a[1:])]