import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String[] t = sc.nextLine().split(" ");
		int n = Integer.parseInt(t[0]);
		int k = Integer.parseInt(t[1]);

		String[] x = sc.nextLine().split(" ");
		int[] list = new int[k];
		int max = 0;

		for(int i = 0; i < k; i++) {
			list[i] = Integer.parseInt(x[i]);
		}

		for(int i = 0; i < k; i++) {
			if(i != 0 && i != k-1) {

				max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i]));
			}
		}
		System.out.println(n - Math.max(max, n - list[k - 1] + list[0]) );
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String[] t = sc.nextLine().split(" ");
		int n = Integer.parseInt(t[0]);
		int k = Integer.parseInt(t[1]);

		String[] x = sc.nextLine().split(" ");
		int[] list = new int[k];
		int max = 0;

		for(int i = 0; i < k; i++) {
			list[i] = Integer.parseInt(x[i]);
		}

		for(int i = 0; i < k; i++) {
			if(i != 0 && i != k-1) {

				max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i]));
			}
		}
		System.out.println(n - Math.max(max, n - list[k - 1] + list[0]) );
	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String[] t = sc.nextLine().split(" ");
		int n = Integer.parseInt(t[0]);
		int k = Integer.parseInt(t[1]);

		String[] x = sc.nextLine().split(" ");
		int[] list = new int[k];
		int max = 0;

		for(int i = 0; i < k; i++) {
			list[i] = Integer.parseInt(x[i]);
		}

		for(int i = 0; i < k; i++) {
			if(i != 0 && i != k-1) {

				max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i]));
			}
		}
		System.out.println(n - Math.max(max, n - list[k - 1] + list[0]) );
	} main {

		Scanner sc = new Scanner(System.in);

		String[] t = sc.nextLine().split(" ");
		int n = Integer.parseInt(t[0]);
		int k = Integer.parseInt(t[1]);

		String[] x = sc.nextLine().split(" ");
		int[] list = new int[k];
		int max = 0;

		for(int i = 0; i < k; i++) {
			list[i] = Integer.parseInt(x[i]);
		}

		for(int i = 0; i < k; i++) {
			if(i != 0 && i != k-1) {

				max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i]));
			}
		}
		System.out.println(n - Math.max(max, n - list[k - 1] + list[0]) );
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] t = sc.nextLine().split(" "); t sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int n = Integer.parseInt(t[0]); n Integer.parseInt(t[0]) Integer.parseInt Integer t[0] t 0 int k = Integer.parseInt(t[1]); k Integer.parseInt(t[1]) Integer.parseInt Integer t[1] t 1 String[] x = sc.nextLine().split(" "); x sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int[] list = new int[k]; list new int[k] k int max = 0; max 0 for(int i = 0; i < k; i++) {
			list[i] = Integer.parseInt(x[i]);
		} int i = 0; int i = 0; i 0 i < k i k i++ i++ i {
			list[i] = Integer.parseInt(x[i]);
		} {
			list[i] = Integer.parseInt(x[i]);
		} list[i] = Integer.parseInt(x[i]) list[i] list i Integer.parseInt(x[i]) Integer.parseInt Integer x[i] x i for(int i = 0; i < k; i++) {
			if(i != 0 && i != k-1) {

				max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i]));
			}
		} int i = 0; int i = 0; i 0 i < k i k i++ i++ i {
			if(i != 0 && i != k-1) {

				max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i]));
			}
		} {
			if(i != 0 && i != k-1) {

				max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i]));
			}
		} if(i != 0 && i != k-1) {

				max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i]));
			} i != 0 && i != k-1 i != 0 i 0 i != k-1 i k-1 k 1 {

				max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i]));
			} max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i])) max Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i])) Math.max Math max Math.max(list[i] - list[i - 1], list[i + 1] - list[i]) Math.max Math list[i] - list[i - 1] list[i] list i list[i - 1] list i - 1 i 1 list[i + 1] - list[i] list[i + 1] list i + 1 i 1 list[i] list i System.out.println(n - Math.max(max, n - list[k - 1] + list[0]) ) System.out.println System.out System System.out n - Math.max(max, n - list[k - 1] + list[0]) n Math.max(max, n - list[k - 1] + list[0]) Math.max Math max n - list[k - 1] + list[0] n - list[k - 1] n list[k - 1] list k - 1 k 1 list[0] list 0 String[] args args public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String[] t = sc.nextLine().split(" ");
		int n = Integer.parseInt(t[0]);
		int k = Integer.parseInt(t[1]);

		String[] x = sc.nextLine().split(" ");
		int[] list = new int[k];
		int max = 0;

		for(int i = 0; i < k; i++) {
			list[i] = Integer.parseInt(x[i]);
		}

		for(int i = 0; i < k; i++) {
			if(i != 0 && i != k-1) {

				max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i]));
			}
		}
		System.out.println(n - Math.max(max, n - list[k - 1] + list[0]) );
	}
} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String[] t = sc.nextLine().split(" ");
		int n = Integer.parseInt(t[0]);
		int k = Integer.parseInt(t[1]);

		String[] x = sc.nextLine().split(" ");
		int[] list = new int[k];
		int max = 0;

		for(int i = 0; i < k; i++) {
			list[i] = Integer.parseInt(x[i]);
		}

		for(int i = 0; i < k; i++) {
			if(i != 0 && i != k-1) {

				max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i]));
			}
		}
		System.out.println(n - Math.max(max, n - list[k - 1] + list[0]) );
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String[] t = sc.nextLine().split(" ");
		int n = Integer.parseInt(t[0]);
		int k = Integer.parseInt(t[1]);

		String[] x = sc.nextLine().split(" ");
		int[] list = new int[k];
		int max = 0;

		for(int i = 0; i < k; i++) {
			list[i] = Integer.parseInt(x[i]);
		}

		for(int i = 0; i < k; i++) {
			if(i != 0 && i != k-1) {

				max = Math.max(max, Math.max(list[i] - list[i - 1], list[i + 1] - list[i]));
			}
		}
		System.out.println(n - Math.max(max, n - list[k - 1] + list[0]) );
	}
}
