import java.util.Scanner;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    ArrayList<Integer> list = new ArrayList<Integer>();
    
    int len = scnr.nextInt();
    int numHouse = scnr.nextInt();
    for (int i = 0; i < numHouse; i++) {
      list.add(scnr.nextInt());
    }
    
    int betweenLen = 0;
    int maxBetweenLen = list.get(0);
    
    for (int i = 0; i < list.size(); i++) {
      if (i == list.size() - 1) {
        betweenLen = len - list.get(i) + list.get(0);
      }
      else {
        betweenLen = list.get(i + 1) - list.get(i);
      }
      
      // System.out.println(betweenLen);
      
      if (maxBetweenLen < betweenLen) {
        maxBetweenLen = betweenLen;
      }
    }
    
    // System.out.println(len);
    // System.out.println(numHouse);
    // System.out.println(list);
    System.out.println(len - maxBetweenLen);
  }
} import java.util.Scanner; Scanner java.util import java.util.ArrayList; ArrayList java.util public class Main {
  public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    ArrayList<Integer> list = new ArrayList<Integer>();
    
    int len = scnr.nextInt();
    int numHouse = scnr.nextInt();
    for (int i = 0; i < numHouse; i++) {
      list.add(scnr.nextInt());
    }
    
    int betweenLen = 0;
    int maxBetweenLen = list.get(0);
    
    for (int i = 0; i < list.size(); i++) {
      if (i == list.size() - 1) {
        betweenLen = len - list.get(i) + list.get(0);
      }
      else {
        betweenLen = list.get(i + 1) - list.get(i);
      }
      
      // System.out.println(betweenLen);
      
      if (maxBetweenLen < betweenLen) {
        maxBetweenLen = betweenLen;
      }
    }
    
    // System.out.println(len);
    // System.out.println(numHouse);
    // System.out.println(list);
    System.out.println(len - maxBetweenLen);
  }
} Main public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    ArrayList<Integer> list = new ArrayList<Integer>();
    
    int len = scnr.nextInt();
    int numHouse = scnr.nextInt();
    for (int i = 0; i < numHouse; i++) {
      list.add(scnr.nextInt());
    }
    
    int betweenLen = 0;
    int maxBetweenLen = list.get(0);
    
    for (int i = 0; i < list.size(); i++) {
      if (i == list.size() - 1) {
        betweenLen = len - list.get(i) + list.get(0);
      }
      else {
        betweenLen = list.get(i + 1) - list.get(i);
      }
      
      // System.out.println(betweenLen);
      
      if (maxBetweenLen < betweenLen) {
        maxBetweenLen = betweenLen;
      }
    }
    
    // System.out.println(len);
    // System.out.println(numHouse);
    // System.out.println(list);
    System.out.println(len - maxBetweenLen);
  } main {
    Scanner scnr = new Scanner(System.in);
    ArrayList<Integer> list = new ArrayList<Integer>();
    
    int len = scnr.nextInt();
    int numHouse = scnr.nextInt();
    for (int i = 0; i < numHouse; i++) {
      list.add(scnr.nextInt());
    }
    
    int betweenLen = 0;
    int maxBetweenLen = list.get(0);
    
    for (int i = 0; i < list.size(); i++) {
      if (i == list.size() - 1) {
        betweenLen = len - list.get(i) + list.get(0);
      }
      else {
        betweenLen = list.get(i + 1) - list.get(i);
      }
      
      // System.out.println(betweenLen);
      
      if (maxBetweenLen < betweenLen) {
        maxBetweenLen = betweenLen;
      }
    }
    
    // System.out.println(len);
    // System.out.println(numHouse);
    // System.out.println(list);
    System.out.println(len - maxBetweenLen);
  } Scanner scnr = new Scanner(System.in); scnr new Scanner(System.in) ArrayList<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() int len = scnr.nextInt(); len scnr.nextInt() scnr.nextInt scnr int numHouse = scnr.nextInt(); numHouse scnr.nextInt() scnr.nextInt scnr for (int i = 0; i < numHouse; i++) {
      list.add(scnr.nextInt());
    } int i = 0; int i = 0; i 0 i < numHouse i numHouse i++ i++ i {
      list.add(scnr.nextInt());
    } {
      list.add(scnr.nextInt());
    } list.add(scnr.nextInt()) list.add list scnr.nextInt() scnr.nextInt scnr int betweenLen = 0; betweenLen 0 int maxBetweenLen = list.get(0); maxBetweenLen list.get(0) list.get list 0 for (int i = 0; i < list.size(); i++) {
      if (i == list.size() - 1) {
        betweenLen = len - list.get(i) + list.get(0);
      }
      else {
        betweenLen = list.get(i + 1) - list.get(i);
      }
      
      // System.out.println(betweenLen);
      
      if (maxBetweenLen < betweenLen) {
        maxBetweenLen = betweenLen;
      }
    } int i = 0; int i = 0; i 0 i < list.size() i list.size() list.size list i++ i++ i {
      if (i == list.size() - 1) {
        betweenLen = len - list.get(i) + list.get(0);
      }
      else {
        betweenLen = list.get(i + 1) - list.get(i);
      }
      
      // System.out.println(betweenLen);
      
      if (maxBetweenLen < betweenLen) {
        maxBetweenLen = betweenLen;
      }
    } {
      if (i == list.size() - 1) {
        betweenLen = len - list.get(i) + list.get(0);
      }
      else {
        betweenLen = list.get(i + 1) - list.get(i);
      }
      
      // System.out.println(betweenLen);
      
      if (maxBetweenLen < betweenLen) {
        maxBetweenLen = betweenLen;
      }
    } if (i == list.size() - 1) {
        betweenLen = len - list.get(i) + list.get(0);
      }
      else {
        betweenLen = list.get(i + 1) - list.get(i);
      } i == list.size() - 1 i list.size() - 1 list.size() list.size list 1 {
        betweenLen = len - list.get(i) + list.get(0);
      } betweenLen = len - list.get(i) + list.get(0) betweenLen len - list.get(i) + list.get(0) len - list.get(i) len list.get(i) list.get list i list.get(0) list.get list 0 {
        betweenLen = list.get(i + 1) - list.get(i);
      } betweenLen = list.get(i + 1) - list.get(i) betweenLen list.get(i + 1) - list.get(i) list.get(i + 1) list.get list i + 1 i 1 list.get(i) list.get list i if (maxBetweenLen < betweenLen) {
        maxBetweenLen = betweenLen;
      } maxBetweenLen < betweenLen maxBetweenLen betweenLen {
        maxBetweenLen = betweenLen;
      } maxBetweenLen = betweenLen maxBetweenLen betweenLen System.out.println(len - maxBetweenLen) System.out.println System.out System System.out len - maxBetweenLen len maxBetweenLen String[] args args public class Main {
  public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    ArrayList<Integer> list = new ArrayList<Integer>();
    
    int len = scnr.nextInt();
    int numHouse = scnr.nextInt();
    for (int i = 0; i < numHouse; i++) {
      list.add(scnr.nextInt());
    }
    
    int betweenLen = 0;
    int maxBetweenLen = list.get(0);
    
    for (int i = 0; i < list.size(); i++) {
      if (i == list.size() - 1) {
        betweenLen = len - list.get(i) + list.get(0);
      }
      else {
        betweenLen = list.get(i + 1) - list.get(i);
      }
      
      // System.out.println(betweenLen);
      
      if (maxBetweenLen < betweenLen) {
        maxBetweenLen = betweenLen;
      }
    }
    
    // System.out.println(len);
    // System.out.println(numHouse);
    // System.out.println(list);
    System.out.println(len - maxBetweenLen);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    ArrayList<Integer> list = new ArrayList<Integer>();
    
    int len = scnr.nextInt();
    int numHouse = scnr.nextInt();
    for (int i = 0; i < numHouse; i++) {
      list.add(scnr.nextInt());
    }
    
    int betweenLen = 0;
    int maxBetweenLen = list.get(0);
    
    for (int i = 0; i < list.size(); i++) {
      if (i == list.size() - 1) {
        betweenLen = len - list.get(i) + list.get(0);
      }
      else {
        betweenLen = list.get(i + 1) - list.get(i);
      }
      
      // System.out.println(betweenLen);
      
      if (maxBetweenLen < betweenLen) {
        maxBetweenLen = betweenLen;
      }
    }
    
    // System.out.println(len);
    // System.out.println(numHouse);
    // System.out.println(list);
    System.out.println(len - maxBetweenLen);
  }
} Main
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    ArrayList<Integer> list = new ArrayList<Integer>();
    
    int len = scnr.nextInt();
    int numHouse = scnr.nextInt();
    for (int i = 0; i < numHouse; i++) {
      list.add(scnr.nextInt());
    }
    
    int betweenLen = 0;
    int maxBetweenLen = list.get(0);
    
    for (int i = 0; i < list.size(); i++) {
      if (i == list.size() - 1) {
        betweenLen = len - list.get(i) + list.get(0);
      }
      else {
        betweenLen = list.get(i + 1) - list.get(i);
      }
      
      // System.out.println(betweenLen);
      
      if (maxBetweenLen < betweenLen) {
        maxBetweenLen = betweenLen;
      }
    }
    
    // System.out.println(len);
    // System.out.println(numHouse);
    // System.out.println(list);
    System.out.println(len - maxBetweenLen);
  }
}