import sys

read = sys.stdin.buffer.read

k, n, *A = read().split()

far = int(k) + int(A[0]) - int(A[-1])

for x, y in zip(A[1:], A):

    if far < int(x) - int(y):

        far = int(x) - int(y)

print((int(k)-far))
import sys

read = sys.stdin.buffer.read

k, n, *A = list(map(int, read().split()))

far = k + A[0] - A[-1]

for x, y in zip(A[1:], A):

    if far < x - y:

        far = x - y

print((k-far))
import sys

read = sys.stdin.buffer.read
k, n, *A = read().split()
far = int(k) + int(A[0]) - int(A[-1])
for x, y in zip(A[1:], A):
    if far < int(x) - int(y):
        far = int(x) - int(y)
print((int(k) - far))

import sys

read = sys.stdin.buffer.read
k, n, *A = list(map(int, read().split()))
far = k + A[0] - A[-1]
for x, y in zip(A[1:], A):
    if far < x - y:
        far = x - y
print((k - far))

-k, n, *A = read().split() -far = int(k) + int(A[0]) - int(A[-1]) +k, n, *A = list(map(int, read().split())) +far = k + A[0] - A[-1] -    if far < int(x) - int(y): -        far = int(x) - int(y) -print((int(k) - far)) +    if far < x - y: +        far = x - y +print((k - far))