#include <bits/stdc++.h>
using namespace std;
const int MAXN=200010;
int N,M,A[MAXN];
int main()
{
	cin>>M>>N;
	for (int i=1;i<=N;++i) scanf("%d",&A[i]);
	int Ans=A[N]-A[1];
	for (int i=2;i<=N;++i) Ans=min(Ans,M-(A[i]-A[i-1]));
	cout<<Ans<<endl;
	return 0;
}