import sys



read = sys.stdin.read

readline = sys.stdin.readline



K, N, *A = list(map(int, read().split()))

A.append(K + A[0])

D = 0

for i, j in zip(A, A[1:]):

    d = j - i

    if d > D:

        D = d



print((K - D))

import sys



read = sys.stdin.read

readline = sys.stdin.readline



K, N, *A = list(map(int, read().split()))

A.append(K + A[0])

d = [j - i for i, j in zip(A, A[1:])]



print((K - max(d)))

import sys

read = sys.stdin.read
readline = sys.stdin.readline
K, N, *A = list(map(int, read().split()))
A.append(K + A[0])
D = 0
for i, j in zip(A, A[1:]):
    d = j - i
    if d > D:
        D = d
print((K - D))

import sys

read = sys.stdin.read
readline = sys.stdin.readline
K, N, *A = list(map(int, read().split()))
A.append(K + A[0])
d = [j - i for i, j in zip(A, A[1:])]
print((K - max(d)))

-D = 0 -for i, j in zip(A, A[1:]): -    d = j - i -    if d > D: -        D = d -print((K - D)) +d = [j - i for i, j in zip(A, A[1:])] +print((K - max(d)))