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

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

distances = []

total = []



for i in range(N-1):

    distances.append(loc[i+1] - loc[i])



distances.append(loc[0] + K - loc[N-1])



for i in range(N):

    total.append(K - distances[i])



print((min(total)))

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

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

distances = []

total = []



for i in range(N-1):

    distances.append(loc[i+1] - loc[i])



distances.append(loc[0] + K - loc[N-1])

max_dis = max(distances)



print((K - max_dis))

K, N = list(map(int, input().split()))
loc = list(map(int, input().split()))
distances = []
total = []
for i in range(N - 1):
    distances.append(loc[i + 1] - loc[i])
distances.append(loc[0] + K - loc[N - 1])
for i in range(N):
    total.append(K - distances[i])
print((min(total)))

K, N = list(map(int, input().split()))
loc = list(map(int, input().split()))
distances = []
total = []
for i in range(N - 1):
    distances.append(loc[i + 1] - loc[i])
distances.append(loc[0] + K - loc[N - 1])
max_dis = max(distances)
print((K - max_dis))

-for i in range(N): -    total.append(K - distances[i]) -print((min(total))) +max_dis = max(distances) +print((K - max_dis))