import numpy as np



K, N = list(map(int, input().split()))

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



print((K - max(np.diff(np.append(a, a[0] + K)))))

from operator import sub



K, N = list(map(int, input().split()))

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



a.append(a[0] + K)

print((K - max(list(map(sub, a[1:], a[:-1])))))
import numpy as np

K, N = list(map(int, input().split()))
a = np.array(list(map(int, input().split())))
print((K - max(np.diff(np.append(a, a[0] + K)))))

from operator import sub

K, N = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(a[0] + K)
print((K - max(list(map(sub, a[1:], a[:-1])))))

-import numpy as np +from operator import sub -a = np.array(list(map(int, input().split()))) -print((K - max(np.diff(np.append(a, a[0] + K))))) +a = list(map(int, input().split())) +a.append(a[0] + K) +print((K - max(list(map(sub, a[1:], a[:-1])))))