import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int dist = scan.nextInt();
		int home = scan.nextInt();
		int[] kyori = new int[home];
 		
		for(int i = 0; i < home;i++) {
			kyori[i] = scan.nextInt();
			
		}
		
		int min = Math.min(kyori[home -  1] - kyori[0] , dist - kyori[1] + kyori[0]);
		min = Math.min(min, dist - kyori[home - 1] + kyori[home - 2]);
		
		for(int i = 1;i < home - 1 ; i++) {
		min = Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i]));
		
		}
		
		System.out.println(min);
		
	}
	
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int dist = scan.nextInt();
		int home = scan.nextInt();
		int[] kyori = new int[home];
 		
		for(int i = 0; i < home;i++) {
			kyori[i] = scan.nextInt();
			
		}
		
		int min = Math.min(kyori[home -  1] - kyori[0] , dist - kyori[1] + kyori[0]);
		min = Math.min(min, dist - kyori[home - 1] + kyori[home - 2]);
		
		for(int i = 1;i < home - 1 ; i++) {
		min = Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i]));
		
		}
		
		System.out.println(min);
		
	}
	
} Main public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int dist = scan.nextInt();
		int home = scan.nextInt();
		int[] kyori = new int[home];
 		
		for(int i = 0; i < home;i++) {
			kyori[i] = scan.nextInt();
			
		}
		
		int min = Math.min(kyori[home -  1] - kyori[0] , dist - kyori[1] + kyori[0]);
		min = Math.min(min, dist - kyori[home - 1] + kyori[home - 2]);
		
		for(int i = 1;i < home - 1 ; i++) {
		min = Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i]));
		
		}
		
		System.out.println(min);
		
	} main {
		Scanner scan = new Scanner(System.in);
		int dist = scan.nextInt();
		int home = scan.nextInt();
		int[] kyori = new int[home];
 		
		for(int i = 0; i < home;i++) {
			kyori[i] = scan.nextInt();
			
		}
		
		int min = Math.min(kyori[home -  1] - kyori[0] , dist - kyori[1] + kyori[0]);
		min = Math.min(min, dist - kyori[home - 1] + kyori[home - 2]);
		
		for(int i = 1;i < home - 1 ; i++) {
		min = Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i]));
		
		}
		
		System.out.println(min);
		
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int dist = scan.nextInt(); dist scan.nextInt() scan.nextInt scan int home = scan.nextInt(); home scan.nextInt() scan.nextInt scan int[] kyori = new int[home]; kyori new int[home] home for(int i = 0; i < home;i++) {
			kyori[i] = scan.nextInt();
			
		} int i = 0; int i = 0; i 0 i < home i home i++ i++ i {
			kyori[i] = scan.nextInt();
			
		} {
			kyori[i] = scan.nextInt();
			
		} kyori[i] = scan.nextInt() kyori[i] kyori i scan.nextInt() scan.nextInt scan int min = Math.min(kyori[home -  1] - kyori[0] , dist - kyori[1] + kyori[0]); min Math.min(kyori[home -  1] - kyori[0] , dist - kyori[1] + kyori[0]) Math.min Math kyori[home -  1] - kyori[0] kyori[home -  1] kyori home -  1 home 1 kyori[0] kyori 0 dist - kyori[1] + kyori[0] dist - kyori[1] dist kyori[1] kyori 1 kyori[0] kyori 0 min = Math.min(min, dist - kyori[home - 1] + kyori[home - 2]) min Math.min(min, dist - kyori[home - 1] + kyori[home - 2]) Math.min Math min dist - kyori[home - 1] + kyori[home - 2] dist - kyori[home - 1] dist kyori[home - 1] kyori home - 1 home 1 kyori[home - 2] kyori home - 2 home 2 for(int i = 1;i < home - 1 ; i++) {
		min = Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i]));
		
		} int i = 1; int i = 1; i 1 i < home - 1 i home - 1 home 1 i++ i++ i {
		min = Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i]));
		
		} {
		min = Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i]));
		
		} min = Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i])) min Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i])) Math.min Math min Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i]) Math.min Math dist - kyori[i] + kyori[i - 1] dist - kyori[i] dist kyori[i] kyori i kyori[i - 1] kyori i - 1 i 1 dist - kyori[i + 1] + kyori[i] dist - kyori[i + 1] dist kyori[i + 1] kyori i + 1 i 1 kyori[i] kyori i System.out.println(min) System.out.println System.out System System.out min String args[] args public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int dist = scan.nextInt();
		int home = scan.nextInt();
		int[] kyori = new int[home];
 		
		for(int i = 0; i < home;i++) {
			kyori[i] = scan.nextInt();
			
		}
		
		int min = Math.min(kyori[home -  1] - kyori[0] , dist - kyori[1] + kyori[0]);
		min = Math.min(min, dist - kyori[home - 1] + kyori[home - 2]);
		
		for(int i = 1;i < home - 1 ; i++) {
		min = Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i]));
		
		}
		
		System.out.println(min);
		
	}
	
} public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int dist = scan.nextInt();
		int home = scan.nextInt();
		int[] kyori = new int[home];
 		
		for(int i = 0; i < home;i++) {
			kyori[i] = scan.nextInt();
			
		}
		
		int min = Math.min(kyori[home -  1] - kyori[0] , dist - kyori[1] + kyori[0]);
		min = Math.min(min, dist - kyori[home - 1] + kyori[home - 2]);
		
		for(int i = 1;i < home - 1 ; i++) {
		min = Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i]));
		
		}
		
		System.out.println(min);
		
	}
	
} Main
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int dist = scan.nextInt();
		int home = scan.nextInt();
		int[] kyori = new int[home];
 		
		for(int i = 0; i < home;i++) {
			kyori[i] = scan.nextInt();
			
		}
		
		int min = Math.min(kyori[home -  1] - kyori[0] , dist - kyori[1] + kyori[0]);
		min = Math.min(min, dist - kyori[home - 1] + kyori[home - 2]);
		
		for(int i = 1;i < home - 1 ; i++) {
		min = Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i]));
		
		}
		
		System.out.println(min);
		
	}
	
}
