import java.util.*;

public class Main {
    public static int sum(ArrayList<Integer> a){
        int total = 0;
        for(int number : a){
            total += number;
        }
        return total;
    }

    public static int min(ArrayList<Integer> a){
        int min_num = 1000000000;
        for(int number : a){
            if(min_num > number){
                min_num = number;
            }
        }
        return min_num;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int total_distance = sc.nextInt();
        int number_of_points = sc.nextInt();
        ArrayList<Integer> points = new ArrayList<>();
        ArrayList<Integer> point_distance = new ArrayList<>();
        for(int i=0;i < number_of_points;i++){
            int number = sc.nextInt();
            points.add(number);
        }
        for(int i=0;i < number_of_points;i++){
            if(i == 0){
                point_distance.add(points.get(number_of_points-1) - points.get(0));
            }else{
                point_distance.add(total_distance - points.get(i) + points.get(i-1));
            }
        }
        System.out.println(min(point_distance));
    }
} import java.util.*; util.* java public class Main {
    public static int sum(ArrayList<Integer> a){
        int total = 0;
        for(int number : a){
            total += number;
        }
        return total;
    }

    public static int min(ArrayList<Integer> a){
        int min_num = 1000000000;
        for(int number : a){
            if(min_num > number){
                min_num = number;
            }
        }
        return min_num;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int total_distance = sc.nextInt();
        int number_of_points = sc.nextInt();
        ArrayList<Integer> points = new ArrayList<>();
        ArrayList<Integer> point_distance = new ArrayList<>();
        for(int i=0;i < number_of_points;i++){
            int number = sc.nextInt();
            points.add(number);
        }
        for(int i=0;i < number_of_points;i++){
            if(i == 0){
                point_distance.add(points.get(number_of_points-1) - points.get(0));
            }else{
                point_distance.add(total_distance - points.get(i) + points.get(i-1));
            }
        }
        System.out.println(min(point_distance));
    }
} Main public static int sum(ArrayList<Integer> a){
        int total = 0;
        for(int number : a){
            total += number;
        }
        return total;
    } sum {
        int total = 0;
        for(int number : a){
            total += number;
        }
        return total;
    } int total = 0; total 0 for(int number : a){
            total += number;
        } int number a {
            total += number;
        } {
            total += number;
        } total += number total number return total; total ArrayList<Integer> a a public static int min(ArrayList<Integer> a){
        int min_num = 1000000000;
        for(int number : a){
            if(min_num > number){
                min_num = number;
            }
        }
        return min_num;
    } min {
        int min_num = 1000000000;
        for(int number : a){
            if(min_num > number){
                min_num = number;
            }
        }
        return min_num;
    } int min_num = 1000000000; min_num 1000000000 for(int number : a){
            if(min_num > number){
                min_num = number;
            }
        } int number a {
            if(min_num > number){
                min_num = number;
            }
        } {
            if(min_num > number){
                min_num = number;
            }
        } if(min_num > number){
                min_num = number;
            } min_num > number min_num number {
                min_num = number;
            } min_num = number min_num number return min_num; min_num ArrayList<Integer> a a public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int total_distance = sc.nextInt();
        int number_of_points = sc.nextInt();
        ArrayList<Integer> points = new ArrayList<>();
        ArrayList<Integer> point_distance = new ArrayList<>();
        for(int i=0;i < number_of_points;i++){
            int number = sc.nextInt();
            points.add(number);
        }
        for(int i=0;i < number_of_points;i++){
            if(i == 0){
                point_distance.add(points.get(number_of_points-1) - points.get(0));
            }else{
                point_distance.add(total_distance - points.get(i) + points.get(i-1));
            }
        }
        System.out.println(min(point_distance));
    } main {
        Scanner sc = new Scanner(System.in);
        int total_distance = sc.nextInt();
        int number_of_points = sc.nextInt();
        ArrayList<Integer> points = new ArrayList<>();
        ArrayList<Integer> point_distance = new ArrayList<>();
        for(int i=0;i < number_of_points;i++){
            int number = sc.nextInt();
            points.add(number);
        }
        for(int i=0;i < number_of_points;i++){
            if(i == 0){
                point_distance.add(points.get(number_of_points-1) - points.get(0));
            }else{
                point_distance.add(total_distance - points.get(i) + points.get(i-1));
            }
        }
        System.out.println(min(point_distance));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int total_distance = sc.nextInt(); total_distance sc.nextInt() sc.nextInt sc int number_of_points = sc.nextInt(); number_of_points sc.nextInt() sc.nextInt sc ArrayList<Integer> points = new ArrayList<>(); points new ArrayList<>() ArrayList<Integer> point_distance = new ArrayList<>(); point_distance new ArrayList<>() for(int i=0;i < number_of_points;i++){
            int number = sc.nextInt();
            points.add(number);
        } int i=0; int i=0; i 0 i < number_of_points i number_of_points i++ i++ i {
            int number = sc.nextInt();
            points.add(number);
        } {
            int number = sc.nextInt();
            points.add(number);
        } int number = sc.nextInt(); number sc.nextInt() sc.nextInt sc points.add(number) points.add points number for(int i=0;i < number_of_points;i++){
            if(i == 0){
                point_distance.add(points.get(number_of_points-1) - points.get(0));
            }else{
                point_distance.add(total_distance - points.get(i) + points.get(i-1));
            }
        } int i=0; int i=0; i 0 i < number_of_points i number_of_points i++ i++ i {
            if(i == 0){
                point_distance.add(points.get(number_of_points-1) - points.get(0));
            }else{
                point_distance.add(total_distance - points.get(i) + points.get(i-1));
            }
        } {
            if(i == 0){
                point_distance.add(points.get(number_of_points-1) - points.get(0));
            }else{
                point_distance.add(total_distance - points.get(i) + points.get(i-1));
            }
        } if(i == 0){
                point_distance.add(points.get(number_of_points-1) - points.get(0));
            }else{
                point_distance.add(total_distance - points.get(i) + points.get(i-1));
            } i == 0 i 0 {
                point_distance.add(points.get(number_of_points-1) - points.get(0));
            } point_distance.add(points.get(number_of_points-1) - points.get(0)) point_distance.add point_distance points.get(number_of_points-1) - points.get(0) points.get(number_of_points-1) points.get points number_of_points-1 number_of_points 1 points.get(0) points.get points 0 {
                point_distance.add(total_distance - points.get(i) + points.get(i-1));
            } point_distance.add(total_distance - points.get(i) + points.get(i-1)) point_distance.add point_distance total_distance - points.get(i) + points.get(i-1) total_distance - points.get(i) total_distance points.get(i) points.get points i points.get(i-1) points.get points i-1 i 1 System.out.println(min(point_distance)) System.out.println System.out System System.out min(point_distance) min point_distance String[] args args public class Main {
    public static int sum(ArrayList<Integer> a){
        int total = 0;
        for(int number : a){
            total += number;
        }
        return total;
    }

    public static int min(ArrayList<Integer> a){
        int min_num = 1000000000;
        for(int number : a){
            if(min_num > number){
                min_num = number;
            }
        }
        return min_num;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int total_distance = sc.nextInt();
        int number_of_points = sc.nextInt();
        ArrayList<Integer> points = new ArrayList<>();
        ArrayList<Integer> point_distance = new ArrayList<>();
        for(int i=0;i < number_of_points;i++){
            int number = sc.nextInt();
            points.add(number);
        }
        for(int i=0;i < number_of_points;i++){
            if(i == 0){
                point_distance.add(points.get(number_of_points-1) - points.get(0));
            }else{
                point_distance.add(total_distance - points.get(i) + points.get(i-1));
            }
        }
        System.out.println(min(point_distance));
    }
} public class Main {
    public static int sum(ArrayList<Integer> a){
        int total = 0;
        for(int number : a){
            total += number;
        }
        return total;
    }

    public static int min(ArrayList<Integer> a){
        int min_num = 1000000000;
        for(int number : a){
            if(min_num > number){
                min_num = number;
            }
        }
        return min_num;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int total_distance = sc.nextInt();
        int number_of_points = sc.nextInt();
        ArrayList<Integer> points = new ArrayList<>();
        ArrayList<Integer> point_distance = new ArrayList<>();
        for(int i=0;i < number_of_points;i++){
            int number = sc.nextInt();
            points.add(number);
        }
        for(int i=0;i < number_of_points;i++){
            if(i == 0){
                point_distance.add(points.get(number_of_points-1) - points.get(0));
            }else{
                point_distance.add(total_distance - points.get(i) + points.get(i-1));
            }
        }
        System.out.println(min(point_distance));
    }
} Main
import java.util.*;

public class Main {
    public static int sum(ArrayList<Integer> a){
        int total = 0;
        for(int number : a){
            total += number;
        }
        return total;
    }

    public static int min(ArrayList<Integer> a){
        int min_num = 1000000000;
        for(int number : a){
            if(min_num > number){
                min_num = number;
            }
        }
        return min_num;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int total_distance = sc.nextInt();
        int number_of_points = sc.nextInt();
        ArrayList<Integer> points = new ArrayList<>();
        ArrayList<Integer> point_distance = new ArrayList<>();
        for(int i=0;i < number_of_points;i++){
            int number = sc.nextInt();
            points.add(number);
        }
        for(int i=0;i < number_of_points;i++){
            if(i == 0){
                point_distance.add(points.get(number_of_points-1) - points.get(0));
            }else{
                point_distance.add(total_distance - points.get(i) + points.get(i-1));
            }
        }
        System.out.println(min(point_distance));
    }
}