#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include<functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <stack>
#include <deque>
#include <tuple>

#define LL long long
#define pii pair<int,int>
#define pLL pair<LL,LL>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<LL>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<LL>
#define vecpii vector<pii>
#define vecpLL vector<pLL>
#define vecbL vector<bool>
#define endl "\n"
#define REP(e,v) for(auto e:v)
#define rep(i, a, n) for(LL i = a; i < n;i++)



using namespace std;


struct edge {//枝
    LL to,cost;
} ;


struct vertex{//頂点(枝付き)
	LL key;
    vector<edge> edges;
};

typedef vector<vertex> graph;//グラフ(枝付き頂点の集合として扱う)

edge edge_init(LL t,LL cos){//枝の初期化
	edge e = {.to = t, .cost = cos};

	return e;

}

vertex vertex_init(LL key,vector<edge> E){//頂点の初期化
	vertex v;

	v.key = key;

	rep(i, 0, E.size()){
				v.edges.push_back(E[i]);
	}

	return v;

}

vector<vertex> graph_init(LL V, LL key[],vector<edge> E[]){//グラフの初期化

	graph G;

	rep(i,0,V){
		vertex v = vertex_init(key[i],E[i]);
		G.push_back(v);
	}

	return G;

}

void dijkstra(LL s,LL V,vector<vertex> G, LL d[]) {

    priority_queue<pLL, vector<pLL>, greater<pLL> > que;

    fill(d,d+V,LLONG_MAX);
    d[s] = 0;
    que.push(pLL(0, s));

    while (!que.empty()) {
        pLL p = que.top();
        que.pop();
        LL v = p.second;
        if (d[v] < p.first) continue;

        rep(i,0, G[v].edges.size()) {
            edge e = G[v].edges[i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(pLL(d[e.to], e.to));
            }
        }
    }

    return;
}



int inp(){
	int x;
	scanf("%d",&x);
	return x;
}
LL linp(){
	LL x;
	scanf("%lld",&x);
	return x;
}

void outp(int i){
	printf("%d",i);
}

void loutp(LL i){
	printf("%lld",i);
}

LL mod(LL i){
	return i % 1000000007;
}


LL gcd(LL i,LL j){
	if(j != 0)
		return gcd(j, i % j);
	else
		return i;

}

LL A(){
	string S;

	cin >> S;

	if(S[2] == S[3] && S[4] == S[5])
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

LL B(){

	LL X;

	cin >> X;

	cout << (X/500) * 1000 + ((X % 500)/5)*5;

	return 0;
}

LL C(){

	LL K,N;

	cin >> K >> N;

	LL A[N];

	LL ma = 0;
	rep(i,0,N){
		cin >> A[i];
	}

	sort(A,A+N);

	rep(i,0,N){
		if(0 < i)
				ma = max(ma,A[i] - A[i-1]);
	}


	ma = max(ma,A[0] - (A[N-1] - K));

	cout << K - ma;

	return 0;
}

LL D(){
	 LL V, X, Y;

	 cin >> V >> X >> Y;



	 LL key[V] = {0};
	 vector<edge> E[V];


	 rep(i,0,V-1){
		E[i].push_back(edge_init(i+1,1));
		E[i+1].push_back(edge_init(i,1));
	 }

	 E[X-1].push_back(edge_init(Y-1,1));
	 E[Y-1].push_back(edge_init(X-1,1));

	 graph G = graph_init(V,key,E);

	 LL d[V][V];//d[i][j]はiからjへの最短距離が入る
	 LL count[V] = {0};

	 rep(i,0,V){
		 dijkstra(i,V,G,d[i]);

	 }

	 rep(i,0,V){
		 rep(j,i+1,V){
			  count[d[i][j]]++;

		 }
	 }

	 rep(i,1,V){
		 cout << count[i] << endl;
	 }

	return 0;
}

LL E(){

	return 0;
}

signed main() {
	//A();
	//B();
	C();
	//D();
	//E();
	return 0;
}


Measured memory_bytes: 1792