Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K, N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

b = A[0]+(K-A[N-1])

for i in range(1,N):
    a = max(A[i]-A[i-1])

c = max(a,b)

print(K-c)


K,N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

c = A[0]+(K-A[N-1])

for i in range(1,N):
    d = max(d,A[i]-A[i-1])

print(K-d)


K, N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

a = [A[i]-A[i-1] for i in range(1,N-1)]

b = A[0]+(K-A[N-1])

print(K-max(a,b))


k,n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

c = a[0] + (k - a[n-1])

c = max(c,[a[i]-a[i-1] for i in range(1,n)])

print(k-c)


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

for i in range[N]:
    dif = A[i+1]-A[i]

dif.extend([K-A[N]])

print(K-max(dif))


k,n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

c = a[0] + (k - a[n - 1])

d = max(c,[a[i] - a[i - 1] for i in range(1, n)])

print(k - d)


K, N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

a = [A[i]-A[i-1] for i in range(1,N)]

b = A[0]+(K-A[N-1])

c = max(a,b)

print(K-c)


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

dif = [A[i+1]-A[i] for i in range(N-1)]

dif.extend([K-A[N]])

print(K-max(dif))


k,n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

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

c = [a[i]-a[i-1] for i in range(1,n)]

print(max(b,c))


k,n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

c = a[0] + (K - a[n-1])

for i in range(1,N):
    d = max(c, A[i] - A[i-1])

print(K - d)


k,n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

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

c = [a[i]-a[i-1] for i in range(1,n)]

d = max(b,c)

print(d)


K,N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

c = A[0]+(K-A[N-1])

for i in range(1,N+1):
    d = max(c,A[i]-A[i-1])

print(K-d)


K, N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

b = A[0]+(K-A[N-1])

a = [A[i]-A[i-1] for i in range(1,N)]

c = max(a,b)

print(K-c)


K, N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

a = [A[i]-A[i-1] for i in range(1,N)]

b = A[0]+(K-A[N-1])

c = max(a,b)

print(K-c)


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

for i in range(N):
    dif = A[i+1]-A[i]

dif.extend([K-A[N]])

print(K-max(dif))

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

dif = [A[i+1]-A[i] for i in range(N)]

dif.extend([K-A[N]])

print(K-max(dif))


k,n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

c = a[0] + (k - a[n - 1])

d = max([a[i] - a[i - 1] for i in range(1, n)])

c = max(c,d)

print(k - c)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted