import java.util.Scanner;

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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        int n = in.nextInt();
        int a[] = new int[200009];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        a[n] = k + a[0];
        int ans = 1000000009;
        for (int i = 0; i < n; i++) {
            ans = Math.min(ans, k - (a[i+1] - a[i]));
        }
        System.out.println(ans);
    }
}
