
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
		int y = sc.nextInt();

		int[] a = new int[n];
		for( int i=0 ; i<y ; i++ ) {
			a[i] = sc.nextInt();
		}
		Calc res = new Calc(n,y, a);
		System.out.println( res.toString() );
	}
	public static class Calc {
		int K;
		int N;
		
		int[] A;
		
		int start;
		int end;
		
		int dist;
		public Calc(int k, int n, int[] a) {
			K = k;
			N = n;
			A = a;
			
			int dist = K - a[n-1] + a[0];
			start = 0;
			for( int i=0 ; i<n-1 ; i++ ) {
				if( dist < a[i+1] - a[i] ) {
					start = i+1;
					dist = a[i+1] - a[i];
				}
			}
//			
//			dist = (K + a[start -1] - a[start]) % K;
			
			this.dist = K - dist;
		}



		@Override
		public String toString() {
			return ""+ dist;
		}
		
		

	}
	
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
		int y = sc.nextInt();

		int[] a = new int[n];
		for( int i=0 ; i<y ; i++ ) {
			a[i] = sc.nextInt();
		}
		Calc res = new Calc(n,y, a);
		System.out.println( res.toString() );
	}
	public static class Calc {
		int K;
		int N;
		
		int[] A;
		
		int start;
		int end;
		
		int dist;
		public Calc(int k, int n, int[] a) {
			K = k;
			N = n;
			A = a;
			
			int dist = K - a[n-1] + a[0];
			start = 0;
			for( int i=0 ; i<n-1 ; i++ ) {
				if( dist < a[i+1] - a[i] ) {
					start = i+1;
					dist = a[i+1] - a[i];
				}
			}
//			
//			dist = (K + a[start -1] - a[start]) % K;
			
			this.dist = K - dist;
		}



		@Override
		public String toString() {
			return ""+ dist;
		}
		
		

	}
	
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
		int y = sc.nextInt();

		int[] a = new int[n];
		for( int i=0 ; i<y ; i++ ) {
			a[i] = sc.nextInt();
		}
		Calc res = new Calc(n,y, a);
		System.out.println( res.toString() );
	} main {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
		int y = sc.nextInt();

		int[] a = new int[n];
		for( int i=0 ; i<y ; i++ ) {
			a[i] = sc.nextInt();
		}
		Calc res = new Calc(n,y, a);
		System.out.println( res.toString() );
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int y = sc.nextInt(); y sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n for( int i=0 ; i<y ; i++ ) {
			a[i] = sc.nextInt();
		} int i=0 ; int i=0 ; i 0 i<y i y i++ i++ i {
			a[i] = sc.nextInt();
		} {
			a[i] = sc.nextInt();
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc Calc res = new Calc(n,y, a); res new Calc(n,y, a) System.out.println( res.toString() ) System.out.println System.out System System.out res.toString() res.toString res String[] args args public static class Calc {
		int K;
		int N;
		
		int[] A;
		
		int start;
		int end;
		
		int dist;
		public Calc(int k, int n, int[] a) {
			K = k;
			N = n;
			A = a;
			
			int dist = K - a[n-1] + a[0];
			start = 0;
			for( int i=0 ; i<n-1 ; i++ ) {
				if( dist < a[i+1] - a[i] ) {
					start = i+1;
					dist = a[i+1] - a[i];
				}
			}
//			
//			dist = (K + a[start -1] - a[start]) % K;
			
			this.dist = K - dist;
		}



		@Override
		public String toString() {
			return ""+ dist;
		}
		
		

	} Calc int K; K int N; N int[] A; A int start; start int end; end int dist; dist public Calc(int k, int n, int[] a) {
			K = k;
			N = n;
			A = a;
			
			int dist = K - a[n-1] + a[0];
			start = 0;
			for( int i=0 ; i<n-1 ; i++ ) {
				if( dist < a[i+1] - a[i] ) {
					start = i+1;
					dist = a[i+1] - a[i];
				}
			}
//			
//			dist = (K + a[start -1] - a[start]) % K;
			
			this.dist = K - dist;
		} Calc {
			K = k;
			N = n;
			A = a;
			
			int dist = K - a[n-1] + a[0];
			start = 0;
			for( int i=0 ; i<n-1 ; i++ ) {
				if( dist < a[i+1] - a[i] ) {
					start = i+1;
					dist = a[i+1] - a[i];
				}
			}
//			
//			dist = (K + a[start -1] - a[start]) % K;
			
			this.dist = K - dist;
		} K = k K k N = n N n A = a A a int dist = K - a[n-1] + a[0]; dist K - a[n-1] + a[0] K - a[n-1] K a[n-1] a n-1 n 1 a[0] a 0 start = 0 start 0 for( int i=0 ; i<n-1 ; i++ ) {
				if( dist < a[i+1] - a[i] ) {
					start = i+1;
					dist = a[i+1] - a[i];
				}
			} int i=0 ; int i=0 ; i 0 i<n-1 i n-1 n 1 i++ i++ i {
				if( dist < a[i+1] - a[i] ) {
					start = i+1;
					dist = a[i+1] - a[i];
				}
			} {
				if( dist < a[i+1] - a[i] ) {
					start = i+1;
					dist = a[i+1] - a[i];
				}
			} if( dist < a[i+1] - a[i] ) {
					start = i+1;
					dist = a[i+1] - a[i];
				} dist < a[i+1] - a[i] dist a[i+1] - a[i] a[i+1] a i+1 i 1 a[i] a i {
					start = i+1;
					dist = a[i+1] - a[i];
				} start = i+1 start i+1 i 1 dist = a[i+1] - a[i] dist a[i+1] - a[i] a[i+1] a i+1 i 1 a[i] a i this.dist = K - dist this.dist this this.dist K - dist K dist int k k int n n int[] a a @Override
		public String toString() {
			return ""+ dist;
		} toString {
			return ""+ dist;
		} return ""+ dist; ""+ dist "" dist public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
		int y = sc.nextInt();

		int[] a = new int[n];
		for( int i=0 ; i<y ; i++ ) {
			a[i] = sc.nextInt();
		}
		Calc res = new Calc(n,y, a);
		System.out.println( res.toString() );
	}
	public static class Calc {
		int K;
		int N;
		
		int[] A;
		
		int start;
		int end;
		
		int dist;
		public Calc(int k, int n, int[] a) {
			K = k;
			N = n;
			A = a;
			
			int dist = K - a[n-1] + a[0];
			start = 0;
			for( int i=0 ; i<n-1 ; i++ ) {
				if( dist < a[i+1] - a[i] ) {
					start = i+1;
					dist = a[i+1] - a[i];
				}
			}
//			
//			dist = (K + a[start -1] - a[start]) % K;
			
			this.dist = K - dist;
		}



		@Override
		public String toString() {
			return ""+ dist;
		}
		
		

	}
	
} public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
		int y = sc.nextInt();

		int[] a = new int[n];
		for( int i=0 ; i<y ; i++ ) {
			a[i] = sc.nextInt();
		}
		Calc res = new Calc(n,y, a);
		System.out.println( res.toString() );
	}
	public static class Calc {
		int K;
		int N;
		
		int[] A;
		
		int start;
		int end;
		
		int dist;
		public Calc(int k, int n, int[] a) {
			K = k;
			N = n;
			A = a;
			
			int dist = K - a[n-1] + a[0];
			start = 0;
			for( int i=0 ; i<n-1 ; i++ ) {
				if( dist < a[i+1] - a[i] ) {
					start = i+1;
					dist = a[i+1] - a[i];
				}
			}
//			
//			dist = (K + a[start -1] - a[start]) % K;
			
			this.dist = K - dist;
		}



		@Override
		public String toString() {
			return ""+ dist;
		}
		
		

	}
	
} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
		int y = sc.nextInt();

		int[] a = new int[n];
		for( int i=0 ; i<y ; i++ ) {
			a[i] = sc.nextInt();
		}
		Calc res = new Calc(n,y, a);
		System.out.println( res.toString() );
	}
	public static class Calc {
		int K;
		int N;
		
		int[] A;
		
		int start;
		int end;
		
		int dist;
		public Calc(int k, int n, int[] a) {
			K = k;
			N = n;
			A = a;
			
			int dist = K - a[n-1] + a[0];
			start = 0;
			for( int i=0 ; i<n-1 ; i++ ) {
				if( dist < a[i+1] - a[i] ) {
					start = i+1;
					dist = a[i+1] - a[i];
				}
			}
//			
//			dist = (K + a[start -1] - a[start]) % K;
			
			this.dist = K - dist;
		}



		@Override
		public String toString() {
			return ""+ dist;
		}
		
		

	}
	
}