#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n,k,a,b,c,t=0,i;
  cin >> k >> n;
  cin >> b;
  c=b;
  for(i=1;i<n;i++){
    cin >> a;
    t=max(t,a-b);
    b=a;
  }
  t=max(t,k+c-b);
  cout << k-t << endl;
  return 0;
}