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);
		int allMeters = sc.nextInt();
		int numberOfHouse = sc.nextInt();

		int[] housePlase = new int[numberOfHouse];
		List<Integer> moveMeters = new ArrayList<>();
		int allMoveMeters = 0;

		for(int i = 0; i < numberOfHouse; i++) {
			 housePlase[i] = sc.nextInt();
		}
		for(int i = numberOfHouse - 1; i > 0; i--) {
			moveMeters.add(housePlase[i] - housePlase[i - 1]);
		}
		moveMeters.add(allMeters - housePlase[numberOfHouse - 1] + housePlase[0]);
		Collections.sort(moveMeters, Collections.reverseOrder());
		int count = 0;
		for(int li : moveMeters) {
			count++;
			if(count != 1) allMoveMeters = allMoveMeters + li;
		}
		System.out.println(allMoveMeters);
	}
} 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);
		int allMeters = sc.nextInt();
		int numberOfHouse = sc.nextInt();

		int[] housePlase = new int[numberOfHouse];
		List<Integer> moveMeters = new ArrayList<>();
		int allMoveMeters = 0;

		for(int i = 0; i < numberOfHouse; i++) {
			 housePlase[i] = sc.nextInt();
		}
		for(int i = numberOfHouse - 1; i > 0; i--) {
			moveMeters.add(housePlase[i] - housePlase[i - 1]);
		}
		moveMeters.add(allMeters - housePlase[numberOfHouse - 1] + housePlase[0]);
		Collections.sort(moveMeters, Collections.reverseOrder());
		int count = 0;
		for(int li : moveMeters) {
			count++;
			if(count != 1) allMoveMeters = allMoveMeters + li;
		}
		System.out.println(allMoveMeters);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int allMeters = sc.nextInt();
		int numberOfHouse = sc.nextInt();

		int[] housePlase = new int[numberOfHouse];
		List<Integer> moveMeters = new ArrayList<>();
		int allMoveMeters = 0;

		for(int i = 0; i < numberOfHouse; i++) {
			 housePlase[i] = sc.nextInt();
		}
		for(int i = numberOfHouse - 1; i > 0; i--) {
			moveMeters.add(housePlase[i] - housePlase[i - 1]);
		}
		moveMeters.add(allMeters - housePlase[numberOfHouse - 1] + housePlase[0]);
		Collections.sort(moveMeters, Collections.reverseOrder());
		int count = 0;
		for(int li : moveMeters) {
			count++;
			if(count != 1) allMoveMeters = allMoveMeters + li;
		}
		System.out.println(allMoveMeters);
	} main {
		Scanner sc = new Scanner(System.in);
		int allMeters = sc.nextInt();
		int numberOfHouse = sc.nextInt();

		int[] housePlase = new int[numberOfHouse];
		List<Integer> moveMeters = new ArrayList<>();
		int allMoveMeters = 0;

		for(int i = 0; i < numberOfHouse; i++) {
			 housePlase[i] = sc.nextInt();
		}
		for(int i = numberOfHouse - 1; i > 0; i--) {
			moveMeters.add(housePlase[i] - housePlase[i - 1]);
		}
		moveMeters.add(allMeters - housePlase[numberOfHouse - 1] + housePlase[0]);
		Collections.sort(moveMeters, Collections.reverseOrder());
		int count = 0;
		for(int li : moveMeters) {
			count++;
			if(count != 1) allMoveMeters = allMoveMeters + li;
		}
		System.out.println(allMoveMeters);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int allMeters = sc.nextInt(); allMeters sc.nextInt() sc.nextInt sc int numberOfHouse = sc.nextInt(); numberOfHouse sc.nextInt() sc.nextInt sc int[] housePlase = new int[numberOfHouse]; housePlase new int[numberOfHouse] numberOfHouse List<Integer> moveMeters = new ArrayList<>(); moveMeters new ArrayList<>() int allMoveMeters = 0; allMoveMeters 0 for(int i = 0; i < numberOfHouse; i++) {
			 housePlase[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < numberOfHouse i numberOfHouse i++ i++ i {
			 housePlase[i] = sc.nextInt();
		} {
			 housePlase[i] = sc.nextInt();
		} housePlase[i] = sc.nextInt() housePlase[i] housePlase i sc.nextInt() sc.nextInt sc for(int i = numberOfHouse - 1; i > 0; i--) {
			moveMeters.add(housePlase[i] - housePlase[i - 1]);
		} int i = numberOfHouse - 1; int i = numberOfHouse - 1; i numberOfHouse - 1 numberOfHouse 1 i > 0 i 0 i-- i-- i {
			moveMeters.add(housePlase[i] - housePlase[i - 1]);
		} {
			moveMeters.add(housePlase[i] - housePlase[i - 1]);
		} moveMeters.add(housePlase[i] - housePlase[i - 1]) moveMeters.add moveMeters housePlase[i] - housePlase[i - 1] housePlase[i] housePlase i housePlase[i - 1] housePlase i - 1 i 1 moveMeters.add(allMeters - housePlase[numberOfHouse - 1] + housePlase[0]) moveMeters.add moveMeters allMeters - housePlase[numberOfHouse - 1] + housePlase[0] allMeters - housePlase[numberOfHouse - 1] allMeters housePlase[numberOfHouse - 1] housePlase numberOfHouse - 1 numberOfHouse 1 housePlase[0] housePlase 0 Collections.sort(moveMeters, Collections.reverseOrder()) Collections.sort Collections moveMeters Collections.reverseOrder() Collections.reverseOrder Collections int count = 0; count 0 for(int li : moveMeters) {
			count++;
			if(count != 1) allMoveMeters = allMoveMeters + li;
		} int li moveMeters {
			count++;
			if(count != 1) allMoveMeters = allMoveMeters + li;
		} {
			count++;
			if(count != 1) allMoveMeters = allMoveMeters + li;
		} count++ count if(count != 1) allMoveMeters = allMoveMeters + li; count != 1 count 1 allMoveMeters = allMoveMeters + li allMoveMeters allMoveMeters + li allMoveMeters li System.out.println(allMoveMeters) System.out.println System.out System System.out allMoveMeters String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int allMeters = sc.nextInt();
		int numberOfHouse = sc.nextInt();

		int[] housePlase = new int[numberOfHouse];
		List<Integer> moveMeters = new ArrayList<>();
		int allMoveMeters = 0;

		for(int i = 0; i < numberOfHouse; i++) {
			 housePlase[i] = sc.nextInt();
		}
		for(int i = numberOfHouse - 1; i > 0; i--) {
			moveMeters.add(housePlase[i] - housePlase[i - 1]);
		}
		moveMeters.add(allMeters - housePlase[numberOfHouse - 1] + housePlase[0]);
		Collections.sort(moveMeters, Collections.reverseOrder());
		int count = 0;
		for(int li : moveMeters) {
			count++;
			if(count != 1) allMoveMeters = allMoveMeters + li;
		}
		System.out.println(allMoveMeters);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int allMeters = sc.nextInt();
		int numberOfHouse = sc.nextInt();

		int[] housePlase = new int[numberOfHouse];
		List<Integer> moveMeters = new ArrayList<>();
		int allMoveMeters = 0;

		for(int i = 0; i < numberOfHouse; i++) {
			 housePlase[i] = sc.nextInt();
		}
		for(int i = numberOfHouse - 1; i > 0; i--) {
			moveMeters.add(housePlase[i] - housePlase[i - 1]);
		}
		moveMeters.add(allMeters - housePlase[numberOfHouse - 1] + housePlase[0]);
		Collections.sort(moveMeters, Collections.reverseOrder());
		int count = 0;
		for(int li : moveMeters) {
			count++;
			if(count != 1) allMoveMeters = allMoveMeters + li;
		}
		System.out.println(allMoveMeters);
	}
} 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);
		int allMeters = sc.nextInt();
		int numberOfHouse = sc.nextInt();

		int[] housePlase = new int[numberOfHouse];
		List<Integer> moveMeters = new ArrayList<>();
		int allMoveMeters = 0;

		for(int i = 0; i < numberOfHouse; i++) {
			 housePlase[i] = sc.nextInt();
		}
		for(int i = numberOfHouse - 1; i > 0; i--) {
			moveMeters.add(housePlase[i] - housePlase[i - 1]);
		}
		moveMeters.add(allMeters - housePlase[numberOfHouse - 1] + housePlase[0]);
		Collections.sort(moveMeters, Collections.reverseOrder());
		int count = 0;
		for(int li : moveMeters) {
			count++;
			if(count != 1) allMoveMeters = allMoveMeters + li;
		}
		System.out.println(allMoveMeters);
	}
}