import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int circle = sc.nextInt();
        int num = sc.nextInt();
        int[] house = new int[num];
        for (int i = 0; i < house.length; i++){
            house[i] = sc.nextInt();
        }
        int sabun = 0;
        for (int j = 0; j < house.length - 1; j++){
            int sabunCheck = Math.abs( house[j] - house[j + 1]);
            if (sabun < sabunCheck){
                sabun = sabunCheck;
            }
        }
        int sabuncheck2 = 0;
            sabuncheck2 = Math.abs(circle - house[house.length - 1] + house[0]);
        if (sabuncheck2 > sabun){
            System.out.println(circle - sabuncheck2);
        }else {
            System.out.println(circle - sabun);
        }

    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int circle = sc.nextInt();
        int num = sc.nextInt();
        int[] house = new int[num];
        for (int i = 0; i < house.length; i++){
            house[i] = sc.nextInt();
        }
        int sabun = 0;
        for (int j = 0; j < house.length - 1; j++){
            int sabunCheck = Math.abs( house[j] - house[j + 1]);
            if (sabun < sabunCheck){
                sabun = sabunCheck;
            }
        }
        int sabuncheck2 = 0;
            sabuncheck2 = Math.abs(circle - house[house.length - 1] + house[0]);
        if (sabuncheck2 > sabun){
            System.out.println(circle - sabuncheck2);
        }else {
            System.out.println(circle - sabun);
        }

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int circle = sc.nextInt();
        int num = sc.nextInt();
        int[] house = new int[num];
        for (int i = 0; i < house.length; i++){
            house[i] = sc.nextInt();
        }
        int sabun = 0;
        for (int j = 0; j < house.length - 1; j++){
            int sabunCheck = Math.abs( house[j] - house[j + 1]);
            if (sabun < sabunCheck){
                sabun = sabunCheck;
            }
        }
        int sabuncheck2 = 0;
            sabuncheck2 = Math.abs(circle - house[house.length - 1] + house[0]);
        if (sabuncheck2 > sabun){
            System.out.println(circle - sabuncheck2);
        }else {
            System.out.println(circle - sabun);
        }

    } main {
        Scanner sc = new Scanner(System.in);
        int circle = sc.nextInt();
        int num = sc.nextInt();
        int[] house = new int[num];
        for (int i = 0; i < house.length; i++){
            house[i] = sc.nextInt();
        }
        int sabun = 0;
        for (int j = 0; j < house.length - 1; j++){
            int sabunCheck = Math.abs( house[j] - house[j + 1]);
            if (sabun < sabunCheck){
                sabun = sabunCheck;
            }
        }
        int sabuncheck2 = 0;
            sabuncheck2 = Math.abs(circle - house[house.length - 1] + house[0]);
        if (sabuncheck2 > sabun){
            System.out.println(circle - sabuncheck2);
        }else {
            System.out.println(circle - sabun);
        }

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int circle = sc.nextInt(); circle sc.nextInt() sc.nextInt sc int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc int[] house = new int[num]; house new int[num] num for (int i = 0; i < house.length; i++){
            house[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < house.length i house.length house house.length i++ i++ i {
            house[i] = sc.nextInt();
        } {
            house[i] = sc.nextInt();
        } house[i] = sc.nextInt() house[i] house i sc.nextInt() sc.nextInt sc int sabun = 0; sabun 0 for (int j = 0; j < house.length - 1; j++){
            int sabunCheck = Math.abs( house[j] - house[j + 1]);
            if (sabun < sabunCheck){
                sabun = sabunCheck;
            }
        } int j = 0; int j = 0; j 0 j < house.length - 1 j house.length - 1 house.length house house.length 1 j++ j++ j {
            int sabunCheck = Math.abs( house[j] - house[j + 1]);
            if (sabun < sabunCheck){
                sabun = sabunCheck;
            }
        } {
            int sabunCheck = Math.abs( house[j] - house[j + 1]);
            if (sabun < sabunCheck){
                sabun = sabunCheck;
            }
        } int sabunCheck = Math.abs( house[j] - house[j + 1]); sabunCheck Math.abs( house[j] - house[j + 1]) Math.abs Math house[j] - house[j + 1] house[j] house j house[j + 1] house j + 1 j 1 if (sabun < sabunCheck){
                sabun = sabunCheck;
            } sabun < sabunCheck sabun sabunCheck {
                sabun = sabunCheck;
            } sabun = sabunCheck sabun sabunCheck int sabuncheck2 = 0; sabuncheck2 0 sabuncheck2 = Math.abs(circle - house[house.length - 1] + house[0]) sabuncheck2 Math.abs(circle - house[house.length - 1] + house[0]) Math.abs Math circle - house[house.length - 1] + house[0] circle - house[house.length - 1] circle house[house.length - 1] house house.length - 1 house.length house house.length 1 house[0] house 0 if (sabuncheck2 > sabun){
            System.out.println(circle - sabuncheck2);
        }else {
            System.out.println(circle - sabun);
        } sabuncheck2 > sabun sabuncheck2 sabun {
            System.out.println(circle - sabuncheck2);
        } System.out.println(circle - sabuncheck2) System.out.println System.out System System.out circle - sabuncheck2 circle sabuncheck2 {
            System.out.println(circle - sabun);
        } System.out.println(circle - sabun) System.out.println System.out System System.out circle - sabun circle sabun String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int circle = sc.nextInt();
        int num = sc.nextInt();
        int[] house = new int[num];
        for (int i = 0; i < house.length; i++){
            house[i] = sc.nextInt();
        }
        int sabun = 0;
        for (int j = 0; j < house.length - 1; j++){
            int sabunCheck = Math.abs( house[j] - house[j + 1]);
            if (sabun < sabunCheck){
                sabun = sabunCheck;
            }
        }
        int sabuncheck2 = 0;
            sabuncheck2 = Math.abs(circle - house[house.length - 1] + house[0]);
        if (sabuncheck2 > sabun){
            System.out.println(circle - sabuncheck2);
        }else {
            System.out.println(circle - sabun);
        }

    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int circle = sc.nextInt();
        int num = sc.nextInt();
        int[] house = new int[num];
        for (int i = 0; i < house.length; i++){
            house[i] = sc.nextInt();
        }
        int sabun = 0;
        for (int j = 0; j < house.length - 1; j++){
            int sabunCheck = Math.abs( house[j] - house[j + 1]);
            if (sabun < sabunCheck){
                sabun = sabunCheck;
            }
        }
        int sabuncheck2 = 0;
            sabuncheck2 = Math.abs(circle - house[house.length - 1] + house[0]);
        if (sabuncheck2 > sabun){
            System.out.println(circle - sabuncheck2);
        }else {
            System.out.println(circle - sabun);
        }

    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int circle = sc.nextInt();
        int num = sc.nextInt();
        int[] house = new int[num];
        for (int i = 0; i < house.length; i++){
            house[i] = sc.nextInt();
        }
        int sabun = 0;
        for (int j = 0; j < house.length - 1; j++){
            int sabunCheck = Math.abs( house[j] - house[j + 1]);
            if (sabun < sabunCheck){
                sabun = sabunCheck;
            }
        }
        int sabuncheck2 = 0;
            sabuncheck2 = Math.abs(circle - house[house.length - 1] + house[0]);
        if (sabuncheck2 > sabun){
            System.out.println(circle - sabuncheck2);
        }else {
            System.out.println(circle - sabun);
        }

    }
}
