import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int k = sc.nextInt();
		int n = sc.nextInt();
		for(int i=0;n>i;i++) {
			int a=sc.nextInt();
			list.add(a);
		}
		Collections.sort(list);
		int count=0;
		List<Integer> list_check=new ArrayList<Integer>();
		for(int i=0;n-1>i;i++) {
			count=count+list.get(i+1)-list.get(i);
			list_check.add(list.get(i+1)-list.get(i));
		}
		count=count+k+list.get(0)-list.get(n-1);
		list_check.add(k+list.get(0)-list.get(n-1));
		int max = Collections.max(list_check);
		System.out.println(count-max);

	}
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int k = sc.nextInt();
		int n = sc.nextInt();
		for(int i=0;n>i;i++) {
			int a=sc.nextInt();
			list.add(a);
		}
		Collections.sort(list);
		int count=0;
		List<Integer> list_check=new ArrayList<Integer>();
		for(int i=0;n-1>i;i++) {
			count=count+list.get(i+1)-list.get(i);
			list_check.add(list.get(i+1)-list.get(i));
		}
		count=count+k+list.get(0)-list.get(n-1);
		list_check.add(k+list.get(0)-list.get(n-1));
		int max = Collections.max(list_check);
		System.out.println(count-max);

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int k = sc.nextInt();
		int n = sc.nextInt();
		for(int i=0;n>i;i++) {
			int a=sc.nextInt();
			list.add(a);
		}
		Collections.sort(list);
		int count=0;
		List<Integer> list_check=new ArrayList<Integer>();
		for(int i=0;n-1>i;i++) {
			count=count+list.get(i+1)-list.get(i);
			list_check.add(list.get(i+1)-list.get(i));
		}
		count=count+k+list.get(0)-list.get(n-1);
		list_check.add(k+list.get(0)-list.get(n-1));
		int max = Collections.max(list_check);
		System.out.println(count-max);

	} main {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int k = sc.nextInt();
		int n = sc.nextInt();
		for(int i=0;n>i;i++) {
			int a=sc.nextInt();
			list.add(a);
		}
		Collections.sort(list);
		int count=0;
		List<Integer> list_check=new ArrayList<Integer>();
		for(int i=0;n-1>i;i++) {
			count=count+list.get(i+1)-list.get(i);
			list_check.add(list.get(i+1)-list.get(i));
		}
		count=count+k+list.get(0)-list.get(n-1);
		list_check.add(k+list.get(0)-list.get(n-1));
		int max = Collections.max(list_check);
		System.out.println(count-max);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) List<Integer> list=new ArrayList<Integer>(); list new ArrayList<Integer>() int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for(int i=0;n>i;i++) {
			int a=sc.nextInt();
			list.add(a);
		} int i=0; int i=0; i 0 n>i n i i++ i++ i {
			int a=sc.nextInt();
			list.add(a);
		} {
			int a=sc.nextInt();
			list.add(a);
		} int a=sc.nextInt(); a sc.nextInt() sc.nextInt sc list.add(a) list.add list a Collections.sort(list) Collections.sort Collections list int count=0; count 0 List<Integer> list_check=new ArrayList<Integer>(); list_check new ArrayList<Integer>() for(int i=0;n-1>i;i++) {
			count=count+list.get(i+1)-list.get(i);
			list_check.add(list.get(i+1)-list.get(i));
		} int i=0; int i=0; i 0 n-1>i n-1 n 1 i i++ i++ i {
			count=count+list.get(i+1)-list.get(i);
			list_check.add(list.get(i+1)-list.get(i));
		} {
			count=count+list.get(i+1)-list.get(i);
			list_check.add(list.get(i+1)-list.get(i));
		} count=count+list.get(i+1)-list.get(i) count count+list.get(i+1)-list.get(i) count+list.get(i+1) count list.get(i+1) list.get list i+1 i 1 list.get(i) list.get list i list_check.add(list.get(i+1)-list.get(i)) list_check.add list_check list.get(i+1)-list.get(i) list.get(i+1) list.get list i+1 i 1 list.get(i) list.get list i count=count+k+list.get(0)-list.get(n-1) count count+k+list.get(0)-list.get(n-1) count+k+list.get(0) count+k+list.get(0) count k list.get(0) list.get list 0 list.get(n-1) list.get list n-1 n 1 list_check.add(k+list.get(0)-list.get(n-1)) list_check.add list_check k+list.get(0)-list.get(n-1) k+list.get(0) k list.get(0) list.get list 0 list.get(n-1) list.get list n-1 n 1 int max = Collections.max(list_check); max Collections.max(list_check) Collections.max Collections list_check System.out.println(count-max) System.out.println System.out System System.out count-max count max String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int k = sc.nextInt();
		int n = sc.nextInt();
		for(int i=0;n>i;i++) {
			int a=sc.nextInt();
			list.add(a);
		}
		Collections.sort(list);
		int count=0;
		List<Integer> list_check=new ArrayList<Integer>();
		for(int i=0;n-1>i;i++) {
			count=count+list.get(i+1)-list.get(i);
			list_check.add(list.get(i+1)-list.get(i));
		}
		count=count+k+list.get(0)-list.get(n-1);
		list_check.add(k+list.get(0)-list.get(n-1));
		int max = Collections.max(list_check);
		System.out.println(count-max);

	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int k = sc.nextInt();
		int n = sc.nextInt();
		for(int i=0;n>i;i++) {
			int a=sc.nextInt();
			list.add(a);
		}
		Collections.sort(list);
		int count=0;
		List<Integer> list_check=new ArrayList<Integer>();
		for(int i=0;n-1>i;i++) {
			count=count+list.get(i+1)-list.get(i);
			list_check.add(list.get(i+1)-list.get(i));
		}
		count=count+k+list.get(0)-list.get(n-1);
		list_check.add(k+list.get(0)-list.get(n-1));
		int max = Collections.max(list_check);
		System.out.println(count-max);

	}
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int k = sc.nextInt();
		int n = sc.nextInt();
		for(int i=0;n>i;i++) {
			int a=sc.nextInt();
			list.add(a);
		}
		Collections.sort(list);
		int count=0;
		List<Integer> list_check=new ArrayList<Integer>();
		for(int i=0;n-1>i;i++) {
			count=count+list.get(i+1)-list.get(i);
			list_check.add(list.get(i+1)-list.get(i));
		}
		count=count+k+list.get(0)-list.get(n-1);
		list_check.add(k+list.get(0)-list.get(n-1));
		int max = Collections.max(list_check);
		System.out.println(count-max);

	}
}