import java.util.Scanner;

public class Main {

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

		int saisyo = 0;
		int hozon = 0;
		int saidai = 0;
		int saigo = 0;

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();

			if (saidai < a - hozon) {
				saidai = a - hozon;
			}

			if (i == 0) {
				saisyo = a;
			}
			if (i == n - 1) {
				saigo = a;
			}

			hozon = a;
		}

		int kotae2 = k - saidai;
		int kotae3 = saigo - saisyo;

		if (kotae2 < kotae3) {
			System.out.println(kotae2);
		} else {
			System.out.println(kotae3);
		}

		sc.close();
	}

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

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

		int saisyo = 0;
		int hozon = 0;
		int saidai = 0;
		int saigo = 0;

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();

			if (saidai < a - hozon) {
				saidai = a - hozon;
			}

			if (i == 0) {
				saisyo = a;
			}
			if (i == n - 1) {
				saigo = a;
			}

			hozon = a;
		}

		int kotae2 = k - saidai;
		int kotae3 = saigo - saisyo;

		if (kotae2 < kotae3) {
			System.out.println(kotae2);
		} else {
			System.out.println(kotae3);
		}

		sc.close();
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();

		int saisyo = 0;
		int hozon = 0;
		int saidai = 0;
		int saigo = 0;

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();

			if (saidai < a - hozon) {
				saidai = a - hozon;
			}

			if (i == 0) {
				saisyo = a;
			}
			if (i == n - 1) {
				saigo = a;
			}

			hozon = a;
		}

		int kotae2 = k - saidai;
		int kotae3 = saigo - saisyo;

		if (kotae2 < kotae3) {
			System.out.println(kotae2);
		} else {
			System.out.println(kotae3);
		}

		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();

		int saisyo = 0;
		int hozon = 0;
		int saidai = 0;
		int saigo = 0;

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();

			if (saidai < a - hozon) {
				saidai = a - hozon;
			}

			if (i == 0) {
				saisyo = a;
			}
			if (i == n - 1) {
				saigo = a;
			}

			hozon = a;
		}

		int kotae2 = k - saidai;
		int kotae3 = saigo - saisyo;

		if (kotae2 < kotae3) {
			System.out.println(kotae2);
		} else {
			System.out.println(kotae3);
		}

		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int saisyo = 0; saisyo 0 int hozon = 0; hozon 0 int saidai = 0; saidai 0 int saigo = 0; saigo 0 for (int i = 0; i < n; i++) {
			int a = sc.nextInt();

			if (saidai < a - hozon) {
				saidai = a - hozon;
			}

			if (i == 0) {
				saisyo = a;
			}
			if (i == n - 1) {
				saigo = a;
			}

			hozon = a;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int a = sc.nextInt();

			if (saidai < a - hozon) {
				saidai = a - hozon;
			}

			if (i == 0) {
				saisyo = a;
			}
			if (i == n - 1) {
				saigo = a;
			}

			hozon = a;
		} {
			int a = sc.nextInt();

			if (saidai < a - hozon) {
				saidai = a - hozon;
			}

			if (i == 0) {
				saisyo = a;
			}
			if (i == n - 1) {
				saigo = a;
			}

			hozon = a;
		} int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc if (saidai < a - hozon) {
				saidai = a - hozon;
			} saidai < a - hozon saidai a - hozon a hozon {
				saidai = a - hozon;
			} saidai = a - hozon saidai a - hozon a hozon if (i == 0) {
				saisyo = a;
			} i == 0 i 0 {
				saisyo = a;
			} saisyo = a saisyo a if (i == n - 1) {
				saigo = a;
			} i == n - 1 i n - 1 n 1 {
				saigo = a;
			} saigo = a saigo a hozon = a hozon a int kotae2 = k - saidai; kotae2 k - saidai k saidai int kotae3 = saigo - saisyo; kotae3 saigo - saisyo saigo saisyo if (kotae2 < kotae3) {
			System.out.println(kotae2);
		} else {
			System.out.println(kotae3);
		} kotae2 < kotae3 kotae2 kotae3 {
			System.out.println(kotae2);
		} System.out.println(kotae2) System.out.println System.out System System.out kotae2 {
			System.out.println(kotae3);
		} System.out.println(kotae3) System.out.println System.out System System.out kotae3 sc.close() sc.close sc String[] args args public class Main {

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

		int saisyo = 0;
		int hozon = 0;
		int saidai = 0;
		int saigo = 0;

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();

			if (saidai < a - hozon) {
				saidai = a - hozon;
			}

			if (i == 0) {
				saisyo = a;
			}
			if (i == n - 1) {
				saigo = a;
			}

			hozon = a;
		}

		int kotae2 = k - saidai;
		int kotae3 = saigo - saisyo;

		if (kotae2 < kotae3) {
			System.out.println(kotae2);
		} else {
			System.out.println(kotae3);
		}

		sc.close();
	}

} public class Main {

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

		int saisyo = 0;
		int hozon = 0;
		int saidai = 0;
		int saigo = 0;

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();

			if (saidai < a - hozon) {
				saidai = a - hozon;
			}

			if (i == 0) {
				saisyo = a;
			}
			if (i == n - 1) {
				saigo = a;
			}

			hozon = a;
		}

		int kotae2 = k - saidai;
		int kotae3 = saigo - saisyo;

		if (kotae2 < kotae3) {
			System.out.println(kotae2);
		} else {
			System.out.println(kotae3);
		}

		sc.close();
	}

} Main
import java.util.Scanner;

public class Main {

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

		int saisyo = 0;
		int hozon = 0;
		int saidai = 0;
		int saigo = 0;

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();

			if (saidai < a - hozon) {
				saidai = a - hozon;
			}

			if (i == 0) {
				saisyo = a;
			}
			if (i == n - 1) {
				saigo = a;
			}

			hozon = a;
		}

		int kotae2 = k - saidai;
		int kotae3 = saigo - saisyo;

		if (kotae2 < kotae3) {
			System.out.println(kotae2);
		} else {
			System.out.println(kotae3);
		}

		sc.close();
	}

}