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

K,N = inputs[0],inputs[1]



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



max_range = input_lines[0]+(K-input_lines[-1])

for i in range(N):

    if i!=N-1:

        torange = input_lines[i+1]-input_lines[i]

        if torange>max_range:

            max_range = torange

print((K-max_range))

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

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



longest = a_inputs[0]+(k-a_inputs[-1])

for i in range(n-1):

    if a_inputs[i+1]-a_inputs[i]>longest:

        longest = a_inputs[i+1]-a_inputs[i]



print((k-longest))
inputs = [int(i) for i in input().split()]
K, N = inputs[0], inputs[1]
input_lines = [int(i) for i in input().split()]
max_range = input_lines[0] + (K - input_lines[-1])
for i in range(N):
    if i != N - 1:
        torange = input_lines[i + 1] - input_lines[i]
        if torange > max_range:
            max_range = torange
print((K - max_range))

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

-inputs = [int(i) for i in input().split()] -K, N = inputs[0], inputs[1] -input_lines = [int(i) for i in input().split()] -max_range = input_lines[0] + (K - input_lines[-1]) -for i in range(N): -    if i != N - 1: -        torange = input_lines[i + 1] - input_lines[i] -        if torange > max_range: -            max_range = torange -print((K - max_range)) +k, n = list(map(int, input().split())) +a_inputs = [int(a) for a in input().split()] +longest = a_inputs[0] + (k - a_inputs[-1]) +for i in range(n - 1): +    if a_inputs[i + 1] - a_inputs[i] > longest: +        longest = a_inputs[i + 1] - a_inputs[i] +print((k - longest))