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


#define flush  cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define acc (ios::sync_with_stdio(false),cin.tie(0))

#define bl '\n'
#define nl cout<<bl
#define cout1(a) cout<<a<<bl
#define cout2(a,b) cout<<a<<" "<<b<<bl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<bl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<bl
#define print(a,s,e) for(ll i=s;i<=e;i++){ cout<<a[i]<<" "; }
#define rprint(a,s,e) for(ll i=s;i>=e;i--){ cout<<a[i]<<" "; }
#define input(a,s,e) sfor(p,s,e) cin>>a[p]

#define all(v) v.begin(),v.end()

#define ll long long
#define ldb long double
#define db double

#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair

#define pll pair<ll,ll>

#define pldb pair<ldb,ldb>


#define vll vector<ll>
#define vldb vector<ldb>
#define vpll vector< pll >
#define vpldb vector< pldb >

#define pqmin priority_queue<ll,vector<ll>,greater<ll> >
#define pq priority_queue<ll>
#define pqpll priority_queue<pll>
#define pqpllmin priority_queue<pll, vector<pll>, greater<pll> >


#define mll map<ll,ll>
#define mldb map<ldb,ldb>

#define sfor(i,a,b) for (ll i = (a); i <= (b); ++i)
#define rfor(i,b,a) for (ll i = (b); i >= (a); --i)

const ll mod = 1e9+7;
const ll maxn = 5e6+5;
#define llmax LLONG_MAX
#define llmin LLONG_MIN
const ldb PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899863;


ll *fact , *ifact;
bool *prime;
vll primes,pfactors;

void sieve()
{
    ll n = maxn;
    prime = new bool[n+1];
    for(ll i=0;i<=n;i++)
    {
        prime[i]=true;
    }
  prime[0]=false;
    prime[1]=false;
    for (ll p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {

            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (ll p=2; p<=n; p++)
       if (prime[p])
          primes.pb(p);
}

bool primeornot(ll n)
{

    for(ll i=0;primes[i]*primes[i]<=n;i++)
    {
        if(n%primes[i]==0)
        {
            return false;
        }
    }
    return true;
}

void primefactors(ll x)
{
    ll temp =x;

    for(ll i=0;primes[i]*primes[i]<=x;i++)
    {
        if(x%primes[i]==0)
        {

            pfactors.pb(primes[i]);
            while(temp%primes[i]==0)
            {
            	temp /=primes[i];
            }
        }
    }
    if(temp>1 && primeornot(temp) )
    {
    	pfactors.pb(temp);
    }
}

void allfactors(vll &v,ll n)
{
    for(ll i=1;i*i<=n;i++)
	{
        if(n%i==0)
        {
            v.pb(i);
            if(i*i!=n)
            {
                v.pb(n/i);
            }
        }
	}
	sort(v.begin(),v.end());
}

ll power(ll a,ll n)
{
 ll res=1;
 while(n)
{
 if(n%2){
    res=( (res%mod) * (a%mod)) % mod;
 }
    a=( (a%mod) * (a%mod) ) % mod;
    n/=2;
}
res%=mod;
return res;
}

ll modInv(ll a){
	return power(a,mod-2)%mod;
}


void modFact(){
    ll n = maxn;
    ifact=new ll[n+1];
    fact=new ll[n+1];
    fact[0]=fact[1]=1;
    for(int i=2;i<=n;i++){
        fact[i]=(i*fact[i-1])%mod;
    }
    ifact[n]=modInv(fact[n]);
    for(int i=n-1;i>=0;i--){
        ifact[i]=((i+1)*ifact[i+1])%mod;
    }
}

ll ncr(ll n, ll r){
    if(n<r || r<0)
        return 0;
    ll ans=fact[n];
    ans*=ifact[r];
    ans%=mod;
    ans*=ifact[n-r];
    ans%=mod;
    return ans;
}

ll npr(ll n, ll r){
    if(n<r || r<0)
        return 0;
    ll ans=fact[n];
    ans*=ifact[n-r];
    return ans%mod;
}

ll lcm(ll a,ll b){
	ll x=__gcd(a,b);
	a/=x;
	b/=x;
	ll sum=a*b*x;
	return sum;
}

bool myfind(ll *arr,ll l,ll r,ll x)
{
    for(ll i=l;i<=r;i++)
    {
        if(arr[i]==x)
        return true;
    }
    return false;
}

bool ispalindrome(string str,ll l,ll r)
{
    while(l<=r)
    {
        if(str[l]!=str[r])
        return false;
        l++;
        r--;
    }
    return true;
}
void swap(ll *a,ll *b)
{
    ll temp = *a;
    *a=*b;
    *b=temp;
}


void solve()
{
  ll k,n;
  cin>>k>>n;
  ll a[n];
  input(a,0,n-1);
  ll d=llmax;
  sfor(i,0,n-1)
  {
  	if(i==0)
  	{
  		d = min(d,a[n-1]-a[0]);
  	}
  	else
  	{
  		d = min(d,k-(a[i]-a[i-1]));
  	}
  }
  
  cout<<d;
  
    return;

}

int main(){
	acc;

        solve();


    return 0;
}





Measured memory_bytes: 1792