#include<bits/stdc++.h>
using namespace std;

int n, a[2000005], ans = 2e7, k;

int main() {
	cin>>k>>n;
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 2; i <= n; i++) 
	    ans = min(ans, k - a[i] + a[i - 1]);
	ans = min(ans, a[n] - a[1]);
	cout<<ans<<endl;
}