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

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

longest = 0

for i in range(n):

    if i==n-1:

        longest = max(longest, k-a_list[i]+a_list[0])

    else:

        distance = a_list[i+1] - a_list[i]

        longest = max(longest, distance)

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

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

longest = 0



for i in range(n-1):

        distance = a_list[i+1] - a_list[i]

        longest = max(longest, distance)



print((k-max(longest, k-a_list[n-1]+a_list[0])))
k, n = list(map(int, input().split()))
a_list = list(map(int, input().split()))
longest = 0
for i in range(n):
    if i == n - 1:
        longest = max(longest, k - a_list[i] + a_list[0])
    else:
        distance = a_list[i + 1] - a_list[i]
        longest = max(longest, distance)
print((k - longest))

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

-for i in range(n): -    if i == n - 1: -        longest = max(longest, k - a_list[i] + a_list[0]) -    else: -        distance = a_list[i + 1] - a_list[i] -        longest = max(longest, distance) -print((k - longest)) +for i in range(n - 1): +    distance = a_list[i + 1] - a_list[i] +    longest = max(longest, distance) +print((k - max(longest, k - a_list[n - 1] + a_list[0])))