import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n + 1];
    int sum = 0;
    for(int i = 0;i < n;i++){
      a[i] = sc.nextInt();
      if(i == 0){
        b[i] = a[i];
      }else{
        b[i] = a[i] - a[i - 1];
      }
      b[n] = k - a[n - 1];
    }
    int last = b[0] + b[n];
    int max = last;
    for(int j = 1;j < n;j++){
      max = Math.max(max , b[j]);
    }  
    int ans = k - max;
    System.out.println(ans);
  }
} import java.util.Scanner; Scanner 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[] a = new int[n];
    int[] b = new int[n + 1];
    int sum = 0;
    for(int i = 0;i < n;i++){
      a[i] = sc.nextInt();
      if(i == 0){
        b[i] = a[i];
      }else{
        b[i] = a[i] - a[i - 1];
      }
      b[n] = k - a[n - 1];
    }
    int last = b[0] + b[n];
    int max = last;
    for(int j = 1;j < n;j++){
      max = Math.max(max , b[j]);
    }  
    int ans = k - max;
    System.out.println(ans);
  }
} Main public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n + 1];
    int sum = 0;
    for(int i = 0;i < n;i++){
      a[i] = sc.nextInt();
      if(i == 0){
        b[i] = a[i];
      }else{
        b[i] = a[i] - a[i - 1];
      }
      b[n] = k - a[n - 1];
    }
    int last = b[0] + b[n];
    int max = last;
    for(int j = 1;j < n;j++){
      max = Math.max(max , b[j]);
    }  
    int ans = k - max;
    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n + 1];
    int sum = 0;
    for(int i = 0;i < n;i++){
      a[i] = sc.nextInt();
      if(i == 0){
        b[i] = a[i];
      }else{
        b[i] = a[i] - a[i - 1];
      }
      b[n] = k - a[n - 1];
    }
    int last = b[0] + b[n];
    int max = last;
    for(int j = 1;j < n;j++){
      max = Math.max(max , b[j]);
    }  
    int ans = k - max;
    System.out.println(ans);
  } 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[] a = new int[n]; a new int[n] n int[] b = new int[n + 1]; b new int[n + 1] n + 1 n 1 int sum = 0; sum 0 for(int i = 0;i < n;i++){
      a[i] = sc.nextInt();
      if(i == 0){
        b[i] = a[i];
      }else{
        b[i] = a[i] - a[i - 1];
      }
      b[n] = k - a[n - 1];
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      a[i] = sc.nextInt();
      if(i == 0){
        b[i] = a[i];
      }else{
        b[i] = a[i] - a[i - 1];
      }
      b[n] = k - a[n - 1];
    } {
      a[i] = sc.nextInt();
      if(i == 0){
        b[i] = a[i];
      }else{
        b[i] = a[i] - a[i - 1];
      }
      b[n] = k - a[n - 1];
    } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc if(i == 0){
        b[i] = a[i];
      }else{
        b[i] = a[i] - a[i - 1];
      } i == 0 i 0 {
        b[i] = a[i];
      } b[i] = a[i] b[i] b i a[i] a i {
        b[i] = a[i] - a[i - 1];
      } b[i] = a[i] - a[i - 1] b[i] b i a[i] - a[i - 1] a[i] a i a[i - 1] a i - 1 i 1 b[n] = k - a[n - 1] b[n] b n k - a[n - 1] k a[n - 1] a n - 1 n 1 int last = b[0] + b[n]; last b[0] + b[n] b[0] b 0 b[n] b n int max = last; max last for(int j = 1;j < n;j++){
      max = Math.max(max , b[j]);
    } int j = 1; int j = 1; j 1 j < n j n j++ j++ j {
      max = Math.max(max , b[j]);
    } {
      max = Math.max(max , b[j]);
    } max = Math.max(max , b[j]) max Math.max(max , b[j]) Math.max Math max b[j] b j int ans = k - max; ans k - max k max System.out.println(ans) System.out.println System.out System System.out ans 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[] a = new int[n];
    int[] b = new int[n + 1];
    int sum = 0;
    for(int i = 0;i < n;i++){
      a[i] = sc.nextInt();
      if(i == 0){
        b[i] = a[i];
      }else{
        b[i] = a[i] - a[i - 1];
      }
      b[n] = k - a[n - 1];
    }
    int last = b[0] + b[n];
    int max = last;
    for(int j = 1;j < n;j++){
      max = Math.max(max , b[j]);
    }  
    int ans = k - max;
    System.out.println(ans);
  }
} public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n + 1];
    int sum = 0;
    for(int i = 0;i < n;i++){
      a[i] = sc.nextInt();
      if(i == 0){
        b[i] = a[i];
      }else{
        b[i] = a[i] - a[i - 1];
      }
      b[n] = k - a[n - 1];
    }
    int last = b[0] + b[n];
    int max = last;
    for(int j = 1;j < n;j++){
      max = Math.max(max , b[j]);
    }  
    int ans = k - max;
    System.out.println(ans);
  }
} Main
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n + 1];
    int sum = 0;
    for(int i = 0;i < n;i++){
      a[i] = sc.nextInt();
      if(i == 0){
        b[i] = a[i];
      }else{
        b[i] = a[i] - a[i - 1];
      }
      b[n] = k - a[n - 1];
    }
    int last = b[0] + b[n];
    int max = last;
    for(int j = 1;j < n;j++){
      max = Math.max(max , b[j]);
    }  
    int ans = k - max;
    System.out.println(ans);
  }
}