
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author wnqmw
 */
public class Main {
    public static void main(String args[]){
        Scanner kb = new Scanner(System.in);
        
        int length = kb.nextInt(), numhouses = kb.nextInt();
        
        int[] houses = new int[numhouses];
        for(int i = 0; i < numhouses; i++){
            houses[i] = kb.nextInt();
        }
        
        int max = houses[0]+(length-houses[numhouses-1]);
        for(int i = 1; i < numhouses; i++){
            if(max < houses[i]-houses[i-1]){
                max = houses[i]-houses[i-1];
            }
        }
        System.out.println(length-max);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String args[]){
        Scanner kb = new Scanner(System.in);
        
        int length = kb.nextInt(), numhouses = kb.nextInt();
        
        int[] houses = new int[numhouses];
        for(int i = 0; i < numhouses; i++){
            houses[i] = kb.nextInt();
        }
        
        int max = houses[0]+(length-houses[numhouses-1]);
        for(int i = 1; i < numhouses; i++){
            if(max < houses[i]-houses[i-1]){
                max = houses[i]-houses[i-1];
            }
        }
        System.out.println(length-max);
    }
} Main public static void main(String args[]){
        Scanner kb = new Scanner(System.in);
        
        int length = kb.nextInt(), numhouses = kb.nextInt();
        
        int[] houses = new int[numhouses];
        for(int i = 0; i < numhouses; i++){
            houses[i] = kb.nextInt();
        }
        
        int max = houses[0]+(length-houses[numhouses-1]);
        for(int i = 1; i < numhouses; i++){
            if(max < houses[i]-houses[i-1]){
                max = houses[i]-houses[i-1];
            }
        }
        System.out.println(length-max);
    } main {
        Scanner kb = new Scanner(System.in);
        
        int length = kb.nextInt(), numhouses = kb.nextInt();
        
        int[] houses = new int[numhouses];
        for(int i = 0; i < numhouses; i++){
            houses[i] = kb.nextInt();
        }
        
        int max = houses[0]+(length-houses[numhouses-1]);
        for(int i = 1; i < numhouses; i++){
            if(max < houses[i]-houses[i-1]){
                max = houses[i]-houses[i-1];
            }
        }
        System.out.println(length-max);
    } Scanner kb = new Scanner(System.in); kb new Scanner(System.in) int length = kb.nextInt() length kb.nextInt() kb.nextInt kb numhouses = kb.nextInt(); numhouses kb.nextInt() kb.nextInt kb int[] houses = new int[numhouses]; houses new int[numhouses] numhouses for(int i = 0; i < numhouses; i++){
            houses[i] = kb.nextInt();
        } int i = 0; int i = 0; i 0 i < numhouses i numhouses i++ i++ i {
            houses[i] = kb.nextInt();
        } {
            houses[i] = kb.nextInt();
        } houses[i] = kb.nextInt() houses[i] houses i kb.nextInt() kb.nextInt kb int max = houses[0]+(length-houses[numhouses-1]); max houses[0]+(length-houses[numhouses-1]) houses[0] houses 0 (length-houses[numhouses-1]) length houses[numhouses-1] houses numhouses-1 numhouses 1 for(int i = 1; i < numhouses; i++){
            if(max < houses[i]-houses[i-1]){
                max = houses[i]-houses[i-1];
            }
        } int i = 1; int i = 1; i 1 i < numhouses i numhouses i++ i++ i {
            if(max < houses[i]-houses[i-1]){
                max = houses[i]-houses[i-1];
            }
        } {
            if(max < houses[i]-houses[i-1]){
                max = houses[i]-houses[i-1];
            }
        } if(max < houses[i]-houses[i-1]){
                max = houses[i]-houses[i-1];
            } max < houses[i]-houses[i-1] max houses[i]-houses[i-1] houses[i] houses i houses[i-1] houses i-1 i 1 {
                max = houses[i]-houses[i-1];
            } max = houses[i]-houses[i-1] max houses[i]-houses[i-1] houses[i] houses i houses[i-1] houses i-1 i 1 System.out.println(length-max) System.out.println System.out System System.out length-max length max String args[] args public class Main {
    public static void main(String args[]){
        Scanner kb = new Scanner(System.in);
        
        int length = kb.nextInt(), numhouses = kb.nextInt();
        
        int[] houses = new int[numhouses];
        for(int i = 0; i < numhouses; i++){
            houses[i] = kb.nextInt();
        }
        
        int max = houses[0]+(length-houses[numhouses-1]);
        for(int i = 1; i < numhouses; i++){
            if(max < houses[i]-houses[i-1]){
                max = houses[i]-houses[i-1];
            }
        }
        System.out.println(length-max);
    }
} public class Main {
    public static void main(String args[]){
        Scanner kb = new Scanner(System.in);
        
        int length = kb.nextInt(), numhouses = kb.nextInt();
        
        int[] houses = new int[numhouses];
        for(int i = 0; i < numhouses; i++){
            houses[i] = kb.nextInt();
        }
        
        int max = houses[0]+(length-houses[numhouses-1]);
        for(int i = 1; i < numhouses; i++){
            if(max < houses[i]-houses[i-1]){
                max = houses[i]-houses[i-1];
            }
        }
        System.out.println(length-max);
    }
} Main

import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author wnqmw
 */
public class Main {
    public static void main(String args[]){
        Scanner kb = new Scanner(System.in);
        
        int length = kb.nextInt(), numhouses = kb.nextInt();
        
        int[] houses = new int[numhouses];
        for(int i = 0; i < numhouses; i++){
            houses[i] = kb.nextInt();
        }
        
        int max = houses[0]+(length-houses[numhouses-1]);
        for(int i = 1; i < numhouses; i++){
            if(max < houses[i]-houses[i-1]){
                max = houses[i]-houses[i-1];
            }
        }
        System.out.println(length-max);
    }
}
