import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int wayLength = sc.nextInt();
        int houseCnt = sc.nextInt();


        int[] place = new int[houseCnt];

        for(int index=0;index<houseCnt;index++){
            place[index] = sc.nextInt();
        }
        sc.close();
        // max計算
        int[] distance = new int[houseCnt];
        for(int i=0;i<houseCnt-1;i++){
            distance[i] = place[i+1] - place[i];
        }
        distance[houseCnt-1] = place[0] + (wayLength-place[houseCnt-1]);

        int max = distance[0];
        for (int ind=0;ind<houseCnt;ind++){
            if(max < distance[ind]){
                max = distance[ind];
            }
        }

        System.out.println(wayLength-max);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int wayLength = sc.nextInt();
        int houseCnt = sc.nextInt();


        int[] place = new int[houseCnt];

        for(int index=0;index<houseCnt;index++){
            place[index] = sc.nextInt();
        }
        sc.close();
        // max計算
        int[] distance = new int[houseCnt];
        for(int i=0;i<houseCnt-1;i++){
            distance[i] = place[i+1] - place[i];
        }
        distance[houseCnt-1] = place[0] + (wayLength-place[houseCnt-1]);

        int max = distance[0];
        for (int ind=0;ind<houseCnt;ind++){
            if(max < distance[ind]){
                max = distance[ind];
            }
        }

        System.out.println(wayLength-max);
    }
} Main public static void main(String[] args) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int wayLength = sc.nextInt();
        int houseCnt = sc.nextInt();


        int[] place = new int[houseCnt];

        for(int index=0;index<houseCnt;index++){
            place[index] = sc.nextInt();
        }
        sc.close();
        // max計算
        int[] distance = new int[houseCnt];
        for(int i=0;i<houseCnt-1;i++){
            distance[i] = place[i+1] - place[i];
        }
        distance[houseCnt-1] = place[0] + (wayLength-place[houseCnt-1]);

        int max = distance[0];
        for (int ind=0;ind<houseCnt;ind++){
            if(max < distance[ind]){
                max = distance[ind];
            }
        }

        System.out.println(wayLength-max);
    } main {

        // 入力
        Scanner sc = new Scanner(System.in);
        int wayLength = sc.nextInt();
        int houseCnt = sc.nextInt();


        int[] place = new int[houseCnt];

        for(int index=0;index<houseCnt;index++){
            place[index] = sc.nextInt();
        }
        sc.close();
        // max計算
        int[] distance = new int[houseCnt];
        for(int i=0;i<houseCnt-1;i++){
            distance[i] = place[i+1] - place[i];
        }
        distance[houseCnt-1] = place[0] + (wayLength-place[houseCnt-1]);

        int max = distance[0];
        for (int ind=0;ind<houseCnt;ind++){
            if(max < distance[ind]){
                max = distance[ind];
            }
        }

        System.out.println(wayLength-max);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int wayLength = sc.nextInt(); wayLength sc.nextInt() sc.nextInt sc int houseCnt = sc.nextInt(); houseCnt sc.nextInt() sc.nextInt sc int[] place = new int[houseCnt]; place new int[houseCnt] houseCnt for(int index=0;index<houseCnt;index++){
            place[index] = sc.nextInt();
        } int index=0; int index=0; index 0 index<houseCnt index houseCnt index++ index++ index {
            place[index] = sc.nextInt();
        } {
            place[index] = sc.nextInt();
        } place[index] = sc.nextInt() place[index] place index sc.nextInt() sc.nextInt sc sc.close() sc.close sc int[] distance = new int[houseCnt]; distance new int[houseCnt] houseCnt for(int i=0;i<houseCnt-1;i++){
            distance[i] = place[i+1] - place[i];
        } int i=0; int i=0; i 0 i<houseCnt-1 i houseCnt-1 houseCnt 1 i++ i++ i {
            distance[i] = place[i+1] - place[i];
        } {
            distance[i] = place[i+1] - place[i];
        } distance[i] = place[i+1] - place[i] distance[i] distance i place[i+1] - place[i] place[i+1] place i+1 i 1 place[i] place i distance[houseCnt-1] = place[0] + (wayLength-place[houseCnt-1]) distance[houseCnt-1] distance houseCnt-1 houseCnt 1 place[0] + (wayLength-place[houseCnt-1]) place[0] place 0 (wayLength-place[houseCnt-1]) wayLength place[houseCnt-1] place houseCnt-1 houseCnt 1 int max = distance[0]; max distance[0] distance 0 for (int ind=0;ind<houseCnt;ind++){
            if(max < distance[ind]){
                max = distance[ind];
            }
        } int ind=0; int ind=0; ind 0 ind<houseCnt ind houseCnt ind++ ind++ ind {
            if(max < distance[ind]){
                max = distance[ind];
            }
        } {
            if(max < distance[ind]){
                max = distance[ind];
            }
        } if(max < distance[ind]){
                max = distance[ind];
            } max < distance[ind] max distance[ind] distance ind {
                max = distance[ind];
            } max = distance[ind] max distance[ind] distance ind System.out.println(wayLength-max) System.out.println System.out System System.out wayLength-max wayLength max String[] args args public class Main {
    public static void main(String[] args) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int wayLength = sc.nextInt();
        int houseCnt = sc.nextInt();


        int[] place = new int[houseCnt];

        for(int index=0;index<houseCnt;index++){
            place[index] = sc.nextInt();
        }
        sc.close();
        // max計算
        int[] distance = new int[houseCnt];
        for(int i=0;i<houseCnt-1;i++){
            distance[i] = place[i+1] - place[i];
        }
        distance[houseCnt-1] = place[0] + (wayLength-place[houseCnt-1]);

        int max = distance[0];
        for (int ind=0;ind<houseCnt;ind++){
            if(max < distance[ind]){
                max = distance[ind];
            }
        }

        System.out.println(wayLength-max);
    }
} public class Main {
    public static void main(String[] args) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int wayLength = sc.nextInt();
        int houseCnt = sc.nextInt();


        int[] place = new int[houseCnt];

        for(int index=0;index<houseCnt;index++){
            place[index] = sc.nextInt();
        }
        sc.close();
        // max計算
        int[] distance = new int[houseCnt];
        for(int i=0;i<houseCnt-1;i++){
            distance[i] = place[i+1] - place[i];
        }
        distance[houseCnt-1] = place[0] + (wayLength-place[houseCnt-1]);

        int max = distance[0];
        for (int ind=0;ind<houseCnt;ind++){
            if(max < distance[ind]){
                max = distance[ind];
            }
        }

        System.out.println(wayLength-max);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int wayLength = sc.nextInt();
        int houseCnt = sc.nextInt();


        int[] place = new int[houseCnt];

        for(int index=0;index<houseCnt;index++){
            place[index] = sc.nextInt();
        }
        sc.close();
        // max計算
        int[] distance = new int[houseCnt];
        for(int i=0;i<houseCnt-1;i++){
            distance[i] = place[i+1] - place[i];
        }
        distance[houseCnt-1] = place[0] + (wayLength-place[houseCnt-1]);

        int max = distance[0];
        for (int ind=0;ind<houseCnt;ind++){
            if(max < distance[ind]){
                max = distance[ind];
            }
        }

        System.out.println(wayLength-max);
    }
}