import java.util.*;
public class Main {
  
	public static void main(String[] args) {
      
    	Scanner sc = new Scanner(System.in);
      	int k = sc.nextInt();
      	int n = sc.nextInt();
      	int maxDistance = 0;
      	int newPoint;
      	int lastPoint = sc.nextInt();
      	int firstPoint = lastPoint;
      	int distance;
      	for (int i = 0; i <  n; i++) {
          if (i == n - 1) {
            newPoint = firstPoint + k;
          } else {
          	newPoint = sc.nextInt();
          }
          distance = Math.abs(newPoint - lastPoint);
          lastPoint = newPoint;
          maxDistance = maxDistance < distance ? distance : maxDistance;
        }
      System.out.println(k - maxDistance);
    }
 } import java.util.*; util.* java public class Main {
  
	public static void main(String[] args) {
      
    	Scanner sc = new Scanner(System.in);
      	int k = sc.nextInt();
      	int n = sc.nextInt();
      	int maxDistance = 0;
      	int newPoint;
      	int lastPoint = sc.nextInt();
      	int firstPoint = lastPoint;
      	int distance;
      	for (int i = 0; i <  n; i++) {
          if (i == n - 1) {
            newPoint = firstPoint + k;
          } else {
          	newPoint = sc.nextInt();
          }
          distance = Math.abs(newPoint - lastPoint);
          lastPoint = newPoint;
          maxDistance = maxDistance < distance ? distance : maxDistance;
        }
      System.out.println(k - maxDistance);
    }
 } Main public static void main(String[] args) {
      
    	Scanner sc = new Scanner(System.in);
      	int k = sc.nextInt();
      	int n = sc.nextInt();
      	int maxDistance = 0;
      	int newPoint;
      	int lastPoint = sc.nextInt();
      	int firstPoint = lastPoint;
      	int distance;
      	for (int i = 0; i <  n; i++) {
          if (i == n - 1) {
            newPoint = firstPoint + k;
          } else {
          	newPoint = sc.nextInt();
          }
          distance = Math.abs(newPoint - lastPoint);
          lastPoint = newPoint;
          maxDistance = maxDistance < distance ? distance : maxDistance;
        }
      System.out.println(k - maxDistance);
    } main {
      
    	Scanner sc = new Scanner(System.in);
      	int k = sc.nextInt();
      	int n = sc.nextInt();
      	int maxDistance = 0;
      	int newPoint;
      	int lastPoint = sc.nextInt();
      	int firstPoint = lastPoint;
      	int distance;
      	for (int i = 0; i <  n; i++) {
          if (i == n - 1) {
            newPoint = firstPoint + k;
          } else {
          	newPoint = sc.nextInt();
          }
          distance = Math.abs(newPoint - lastPoint);
          lastPoint = newPoint;
          maxDistance = maxDistance < distance ? distance : maxDistance;
        }
      System.out.println(k - maxDistance);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int maxDistance = 0; maxDistance 0 int newPoint; newPoint int lastPoint = sc.nextInt(); lastPoint sc.nextInt() sc.nextInt sc int firstPoint = lastPoint; firstPoint lastPoint int distance; distance for (int i = 0; i <  n; i++) {
          if (i == n - 1) {
            newPoint = firstPoint + k;
          } else {
          	newPoint = sc.nextInt();
          }
          distance = Math.abs(newPoint - lastPoint);
          lastPoint = newPoint;
          maxDistance = maxDistance < distance ? distance : maxDistance;
        } int i = 0; int i = 0; i 0 i <  n i n i++ i++ i {
          if (i == n - 1) {
            newPoint = firstPoint + k;
          } else {
          	newPoint = sc.nextInt();
          }
          distance = Math.abs(newPoint - lastPoint);
          lastPoint = newPoint;
          maxDistance = maxDistance < distance ? distance : maxDistance;
        } {
          if (i == n - 1) {
            newPoint = firstPoint + k;
          } else {
          	newPoint = sc.nextInt();
          }
          distance = Math.abs(newPoint - lastPoint);
          lastPoint = newPoint;
          maxDistance = maxDistance < distance ? distance : maxDistance;
        } if (i == n - 1) {
            newPoint = firstPoint + k;
          } else {
          	newPoint = sc.nextInt();
          } i == n - 1 i n - 1 n 1 {
            newPoint = firstPoint + k;
          } newPoint = firstPoint + k newPoint firstPoint + k firstPoint k {
          	newPoint = sc.nextInt();
          } newPoint = sc.nextInt() newPoint sc.nextInt() sc.nextInt sc distance = Math.abs(newPoint - lastPoint) distance Math.abs(newPoint - lastPoint) Math.abs Math newPoint - lastPoint newPoint lastPoint lastPoint = newPoint lastPoint newPoint maxDistance = maxDistance < distance ? distance : maxDistance maxDistance maxDistance < distance ? distance : maxDistance maxDistance < distance maxDistance distance distance maxDistance System.out.println(k - maxDistance) System.out.println System.out System System.out k - maxDistance k maxDistance String[] args args public class Main {
  
	public static void main(String[] args) {
      
    	Scanner sc = new Scanner(System.in);
      	int k = sc.nextInt();
      	int n = sc.nextInt();
      	int maxDistance = 0;
      	int newPoint;
      	int lastPoint = sc.nextInt();
      	int firstPoint = lastPoint;
      	int distance;
      	for (int i = 0; i <  n; i++) {
          if (i == n - 1) {
            newPoint = firstPoint + k;
          } else {
          	newPoint = sc.nextInt();
          }
          distance = Math.abs(newPoint - lastPoint);
          lastPoint = newPoint;
          maxDistance = maxDistance < distance ? distance : maxDistance;
        }
      System.out.println(k - maxDistance);
    }
 } public class Main {
  
	public static void main(String[] args) {
      
    	Scanner sc = new Scanner(System.in);
      	int k = sc.nextInt();
      	int n = sc.nextInt();
      	int maxDistance = 0;
      	int newPoint;
      	int lastPoint = sc.nextInt();
      	int firstPoint = lastPoint;
      	int distance;
      	for (int i = 0; i <  n; i++) {
          if (i == n - 1) {
            newPoint = firstPoint + k;
          } else {
          	newPoint = sc.nextInt();
          }
          distance = Math.abs(newPoint - lastPoint);
          lastPoint = newPoint;
          maxDistance = maxDistance < distance ? distance : maxDistance;
        }
      System.out.println(k - maxDistance);
    }
 } Main
import java.util.*;
public class Main {
  
	public static void main(String[] args) {
      
    	Scanner sc = new Scanner(System.in);
      	int k = sc.nextInt();
      	int n = sc.nextInt();
      	int maxDistance = 0;
      	int newPoint;
      	int lastPoint = sc.nextInt();
      	int firstPoint = lastPoint;
      	int distance;
      	for (int i = 0; i <  n; i++) {
          if (i == n - 1) {
            newPoint = firstPoint + k;
          } else {
          	newPoint = sc.nextInt();
          }
          distance = Math.abs(newPoint - lastPoint);
          lastPoint = newPoint;
          maxDistance = maxDistance < distance ? distance : maxDistance;
        }
      System.out.println(k - maxDistance);
    }
 }