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

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

ans = k

b = a[0] + (k-a[-1])

prev = a[0]

for i, v in enumerate(a):

    x = 0

    if i == 0:

        x = max(abs(a[i+1]-v), b)

    elif i == len(a)-1:

        x = max(b, abs(v-prev))

    else:

        x = max(abs(a[i+1]-v), abs(v-prev))

    ans = min(ans, k-x)

    prev = v

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

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

ans = k

b = a[0] + (k-a[-1])



prev = a[0]



for i, v in enumerate(a):

    if i == 0:

        ans = min(ans, k-b)

    ans = min(ans, k-abs(v-prev))

    prev = v

    

print(ans)
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = k
b = a[0] + (k - a[-1])
prev = a[0]
for i, v in enumerate(a):
    x = 0
    if i == 0:
        x = max(abs(a[i + 1] - v), b)
    elif i == len(a) - 1:
        x = max(b, abs(v - prev))
    else:
        x = max(abs(a[i + 1] - v), abs(v - prev))
    ans = min(ans, k - x)
    prev = v
print(ans)

k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = k
b = a[0] + (k - a[-1])
prev = a[0]
for i, v in enumerate(a):
    if i == 0:
        ans = min(ans, k - b)
    ans = min(ans, k - abs(v - prev))
    prev = v
print(ans)

-    x = 0 -        x = max(abs(a[i + 1] - v), b) -    elif i == len(a) - 1: -        x = max(b, abs(v - prev)) -    else: -        x = max(abs(a[i + 1] - v), abs(v - prev)) -    ans = min(ans, k - x) +        ans = min(ans, k - b) +    ans = min(ans, k - abs(v - prev))