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

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

diff_a = [0] * n

diff_a[0] = (a[0] + k) - a[n - 1]

for i in range(1, n):

    diff_a[i] = a[i] - a[i - 1]

print((k - max(diff_a)))
k, n = list(map(int, input().split()))

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

a += [k + a[0]]

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

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

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