import java.io. *;
import java.lang.reflect.Array;
import java.util.*;
import static java.lang.Math.*;
public class Main {

    static int visited[];
    static ArrayList<ArrayList<Integer>> adjlist;
    static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    }

    static class Graph{
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;
        int dist[];
        public Graph(int V){
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        }

        void addedge(int u, int v, int w ){
            adj.get(u).add(new edge(v,w));
            adj.get(v).add(new edge(u,w));
        }

        int dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }
            int dis = dist[2];

            return dis;
        }


    }



    static  int I[];
    static  int L[];
    static void LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }
        int lisLength = 1;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int houses[] = new int[m];
        for(int i=0; i<m; i++){
            houses[i] = sc.nextInt();
        }

        Arrays.sort(houses);
        int max = 0;
        for(int i=1; i<m; i++){
            max = Math.max(max,Math.abs(houses[i]-houses[i-1]));
        }
        max = Math.max(max,Math.abs((n+houses[0])-houses[m-1]));
        pw.println(n-max);
        pw.close();

    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    }
}
 
  import java.io. *; io.  java import java.lang.reflect.Array; Array java.lang.reflect import java.util.*; util.* java import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main {

    static int visited[];
    static ArrayList<ArrayList<Integer>> adjlist;
    static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    }

    static class Graph{
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;
        int dist[];
        public Graph(int V){
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        }

        void addedge(int u, int v, int w ){
            adj.get(u).add(new edge(v,w));
            adj.get(v).add(new edge(u,w));
        }

        int dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }
            int dis = dist[2];

            return dis;
        }


    }



    static  int I[];
    static  int L[];
    static void LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }
        int lisLength = 1;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int houses[] = new int[m];
        for(int i=0; i<m; i++){
            houses[i] = sc.nextInt();
        }

        Arrays.sort(houses);
        int max = 0;
        for(int i=1; i<m; i++){
            max = Math.max(max,Math.abs(houses[i]-houses[i-1]));
        }
        max = Math.max(max,Math.abs((n+houses[0])-houses[m-1]));
        pw.println(n-max);
        pw.close();

    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    }
} Main static int visited[]; visited static ArrayList<ArrayList<Integer>> adjlist; adjlist static  int I[]; I static  int L[]; L static void LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }
        int lisLength = 1;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
    } LIS {
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }
        int lisLength = 1;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
    } I = new int[n+1] I new int[n+1] n+1 n 1 L = new int[n] L new int[n] n I[0] = Integer.MIN_VALUE I[0] I 0 Integer.MIN_VALUE Integer Integer.MIN_VALUE for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
            I[i] = Integer.MAX_VALUE;
        } {
            I[i] = Integer.MAX_VALUE;
        } I[i] = Integer.MAX_VALUE I[i] I i Integer.MAX_VALUE Integer Integer.MAX_VALUE int lisLength = 1; lisLength 1 for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        } int i=n-1; int i=n-1; i n-1 n 1 i>=0 i 0 i-- i-- i {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        } {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        } int low = 1; low 1 int high = lisLength; high lisLength int mid = 0; mid 0 while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            } low < high low high {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            } mid = (low + high) >> 1 mid (low + high) >> 1 (low + high) low high 1 if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                } I[mid] <= arr[i] I[mid] I mid arr[i] arr i {
                    high = mid;
                } high = mid high mid {
                    low = mid + 1;
                } low = mid + 1 low mid + 1 mid 1 I[high] = arr[i] I[high] I high arr[i] arr i L[i] = high L[i] L i high if(lisLength<=high){
                lisLength++;
            } lisLength<=high lisLength high {
                lisLength++;
            } lisLength++ lisLength int n n int arr[] arr public static void main(String[] args) {
        FastReader sc = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int houses[] = new int[m];
        for(int i=0; i<m; i++){
            houses[i] = sc.nextInt();
        }

        Arrays.sort(houses);
        int max = 0;
        for(int i=1; i<m; i++){
            max = Math.max(max,Math.abs(houses[i]-houses[i-1]));
        }
        max = Math.max(max,Math.abs((n+houses[0])-houses[m-1]));
        pw.println(n-max);
        pw.close();

    } main {
        FastReader sc = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int houses[] = new int[m];
        for(int i=0; i<m; i++){
            houses[i] = sc.nextInt();
        }

        Arrays.sort(houses);
        int max = 0;
        for(int i=1; i<m; i++){
            max = Math.max(max,Math.abs(houses[i]-houses[i-1]));
        }
        max = Math.max(max,Math.abs((n+houses[0])-houses[m-1]));
        pw.println(n-max);
        pw.close();

    } FastReader sc = new FastReader(System.in); sc new FastReader(System.in) PrintWriter pw = new PrintWriter(System.out); pw new PrintWriter(System.out) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int houses[] = new int[m]; houses new int[m] m for(int i=0; i<m; i++){
            houses[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<m i m i++ i++ i {
            houses[i] = sc.nextInt();
        } {
            houses[i] = sc.nextInt();
        } houses[i] = sc.nextInt() houses[i] houses i sc.nextInt() sc.nextInt sc Arrays.sort(houses) Arrays.sort Arrays houses int max = 0; max 0 for(int i=1; i<m; i++){
            max = Math.max(max,Math.abs(houses[i]-houses[i-1]));
        } int i=1; int i=1; i 1 i<m i m i++ i++ i {
            max = Math.max(max,Math.abs(houses[i]-houses[i-1]));
        } {
            max = Math.max(max,Math.abs(houses[i]-houses[i-1]));
        } max = Math.max(max,Math.abs(houses[i]-houses[i-1])) max Math.max(max,Math.abs(houses[i]-houses[i-1])) Math.max Math max Math.abs(houses[i]-houses[i-1]) Math.abs Math houses[i]-houses[i-1] houses[i] houses i houses[i-1] houses i-1 i 1 max = Math.max(max,Math.abs((n+houses[0])-houses[m-1])) max Math.max(max,Math.abs((n+houses[0])-houses[m-1])) Math.max Math max Math.abs((n+houses[0])-houses[m-1]) Math.abs Math (n+houses[0])-houses[m-1] (n+houses[0]) n houses[0] houses 0 houses[m-1] houses m-1 m 1 pw.println(n-max) pw.println pw n-max n max pw.close() pw.close pw String[] args args static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    } debug {
        System.err.println(Arrays.deepToString(obj));
    } System.err.println(Arrays.deepToString(obj)) System.err.println System.err System System.err Arrays.deepToString(obj) Arrays.deepToString Arrays obj Object...obj obj static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    } edge int dest; dest int cost; cost public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        } edge {
            this.dest = dest;
            this.cost = cost;
        } this.dest = dest this.dest this this.dest dest this.cost = cost this.cost this this.cost cost int dest dest int cost cost @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        } compare {
            return o1.cost-o2.cost;
        } return o1.cost-o2.cost; o1.cost-o2.cost o1.cost o1 o1.cost o2.cost o2 o2.cost edge o1 o1 edge o2 o2 Comparator static class Graph{
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;
        int dist[];
        public Graph(int V){
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        }

        void addedge(int u, int v, int w ){
            adj.get(u).add(new edge(v,w));
            adj.get(v).add(new edge(u,w));
        }

        int dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }
            int dis = dist[2];

            return dis;
        }


    } Graph int V; V ArrayList<ArrayList<edge>> adj; adj PriorityQueue<edge> pq; pq int dist[]; dist public Graph(int V){
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        } Graph {
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        } this.V = V this.V this this.V V adj = new ArrayList<>(V) adj new ArrayList<>(V) pq = new PriorityQueue<>(V,new edge(-1,-1)) pq new PriorityQueue<>(V,new edge(-1,-1)) dist = new int[V] dist new int[V] V for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            } int i=0; int i=0; i 0 i<V i V i++ i++ i {
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            } {
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            } dist[i] = Integer.MAX_VALUE dist[i] dist i Integer.MAX_VALUE Integer Integer.MAX_VALUE adj.add(i,new ArrayList<>()) adj.add adj i new ArrayList<>() int V V void addedge(int u, int v, int w ){
            adj.get(u).add(new edge(v,w));
            adj.get(v).add(new edge(u,w));
        } addedge {
            adj.get(u).add(new edge(v,w));
            adj.get(v).add(new edge(u,w));
        } adj.get(u).add(new edge(v,w)) adj.get(u).add adj.get(u) adj.get adj u new edge(v,w) adj.get(v).add(new edge(u,w)) adj.get(v).add adj.get(v) adj.get adj v new edge(u,w) int u u int v v int w w int dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }
            int dis = dist[2];

            return dis;
        } dijkstra {
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }
            int dis = dist[2];

            return dis;
        } for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            } int i=0; int i=0; i 0 i<V i V i++ i++ i {
                dist[i] = Integer.MAX_VALUE;
            } {
                dist[i] = Integer.MAX_VALUE;
            } dist[i] = Integer.MAX_VALUE dist[i] dist i Integer.MAX_VALUE Integer Integer.MAX_VALUE dist[src] = 0 dist[src] dist src 0 pq.add(new edge(src,0)) pq.add pq new edge(src,0) while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            } !pq.isEmpty() pq.isEmpty() pq.isEmpty pq {
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            } int u = pq.poll().dest; u pq.poll().dest pq.poll() pq.poll pq pq.poll().dest for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                } int i=0; int i=0; i 0 i<adj.get(u).size() i adj.get(u).size() adj.get(u).size adj.get(u) adj.get adj u i++ i++ i {
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                } {
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                } int v = adj.get(u).get(i).dest; v adj.get(u).get(i).dest adj.get(u).get(i) adj.get(u).get adj.get(u) adj.get adj u i adj.get(u).get(i).dest int w = adj.get(u).get(i).cost; w adj.get(u).get(i).cost adj.get(u).get(i) adj.get(u).get adj.get(u) adj.get adj u i adj.get(u).get(i).cost if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    } dist[u]+w<=dist[v] dist[u]+w dist[u] dist u w dist[v] dist v {
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    } dist[v] = dist[u] + w dist[v] dist v dist[u] + w dist[u] dist u w pq.add(new edge(v,dist[v])) pq.add pq new edge(v,dist[v]) int dis = dist[2]; dis dist[2] dist 2 return dis; dis int src src static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    } FastReader InputStream is; is private byte[] inbuf = new byte[1024]; inbuf new byte[1024] 1024 private int lenbuf = 0 lenbuf 0 ptrbuf = 0; ptrbuf 0 public FastReader(InputStream is) {
            this.is = is;
        } FastReader {
            this.is = is;
        } this.is = is this.is this this.is is InputStream is is public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        } readByte {
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        } if(lenbuf == -1)throw new InputMismatchException(); lenbuf == -1 lenbuf -1 1 throw new InputMismatchException(); new InputMismatchException() if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            } ptrbuf >= lenbuf ptrbuf lenbuf {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            } ptrbuf = 0 ptrbuf 0 try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                } catch (IOException e) {
                    throw new InputMismatchException();
                } IOException e {
                    throw new InputMismatchException();
                } throw new InputMismatchException(); new InputMismatchException() {
                    lenbuf = is.read(inbuf);
                } lenbuf = is.read(inbuf) lenbuf is.read(inbuf) is.read is inbuf if(lenbuf <= 0)
                    return -1; lenbuf <= 0 lenbuf 0 return -1; -1 1 return inbuf[ptrbuf++]; inbuf[ptrbuf++] inbuf ptrbuf++ ptrbuf public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        } isSpaceChar {
            return !(c >= 33 && c <= 126);
        } return !(c >= 33 && c <= 126); !(c >= 33 && c <= 126) (c >= 33 && c <= 126) c >= 33 c 33 c <= 126 c 126 int c c public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        } skip {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        } int b; b while ((b = readByte()) != -1 && isSpaceChar(b)) ; (b = readByte()) != -1 && isSpaceChar(b) (b = readByte()) != -1 (b = readByte()) b readByte() readByte -1 1 isSpaceChar(b) isSpaceChar b return b; b public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        } next {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        } int b = skip(); b skip() skip StringBuilder sb = new StringBuilder(); sb new StringBuilder() while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            } !(isSpaceChar(b)) (isSpaceChar(b)) isSpaceChar b {
                sb.appendCodePoint(b);
                b = readByte();
            } sb.appendCodePoint(b) sb.appendCodePoint sb b b = readByte() b readByte() readByte return sb.toString(); sb.toString() sb.toString sb public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        } nextLine {
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        } int b = readByte(); b readByte() readByte StringBuilder sb = new StringBuilder(); sb new StringBuilder() while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            } b != '\n' || b != '\r' b != '\n' b '\n' b != '\r' b '\r' {
                sb.appendCodePoint(b);
            } sb.appendCodePoint(b) sb.appendCodePoint sb b return sb.toString(); sb.toString() sb.toString sb public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        } nextInt {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        } int num = 0 num 0 b; b boolean minus = false; minus false while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; (b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-') (b = readByte()) != -1 (b = readByte()) b readByte() readByte -1 1 !((b >= '0' && b <= '9') || b == '-') ((b >= '0' && b <= '9') || b == '-') (b >= '0' && b <= '9') b >= '0' b '0' b <= '9' b '9' b == '-' b '-' if (b == '-') {
                minus = true;
                b = readByte();
            } b == '-' b '-' {
                minus = true;
                b = readByte();
            } minus = true minus true b = readByte() b readByte() readByte while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            } true {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            } if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                } b >= '0' && b <= '9' b >= '0' b '0' b <= '9' b '9' {
                    num = (num << 3) + (num << 1) + (b - '0');
                } num = (num << 3) + (num << 1) + (b - '0') num (num << 3) + (num << 1) + (b - '0') (num << 3) + (num << 1) + (b - '0') (num << 3) num 3 (num << 1) num 1 (b - '0') b '0' {
                    return minus ? -num : num;
                } return minus ? -num : num; minus ? -num : num minus -num num num b = readByte() b readByte() readByte public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        } nextLong {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        } long num = 0; num 0 int b; b boolean minus = false; minus false while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; (b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-') (b = readByte()) != -1 (b = readByte()) b readByte() readByte -1 1 !((b >= '0' && b <= '9') || b == '-') ((b >= '0' && b <= '9') || b == '-') (b >= '0' && b <= '9') b >= '0' b '0' b <= '9' b '9' b == '-' b '-' if (b == '-') {
                minus = true;
                b = readByte();
            } b == '-' b '-' {
                minus = true;
                b = readByte();
            } minus = true minus true b = readByte() b readByte() readByte while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            } true {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            } if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                } b >= '0' && b <= '9' b >= '0' b '0' b <= '9' b '9' {
                    num = (num << 3) + (num << 1) + (b - '0');
                } num = (num << 3) + (num << 1) + (b - '0') num (num << 3) + (num << 1) + (b - '0') (num << 3) + (num << 1) + (b - '0') (num << 3) num 3 (num << 1) num 1 (b - '0') b '0' {
                    return minus ? -num : num;
                } return minus ? -num : num; minus ? -num : num minus -num num num b = readByte() b readByte() readByte public double nextDouble() {
            return Double.parseDouble(next());
        } nextDouble {
            return Double.parseDouble(next());
        } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        } next {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        } char[] buf = new char[n]; buf new char[n] n int b = skip() b skip() skip p = 0; p 0 while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            } p < n && !(isSpaceChar(b)) p < n p n !(isSpaceChar(b)) (isSpaceChar(b)) isSpaceChar b {
                buf[p++] = (char) b;
                b = readByte();
            } buf[p++] = (char) b buf[p++] buf p++ p (char) b b = readByte() b readByte() readByte return n == p ? buf : Arrays.copyOf(buf, p); n == p ? buf : Arrays.copyOf(buf, p) n == p n p buf Arrays.copyOf(buf, p) Arrays.copyOf Arrays buf p int n n public char nextChar () {
            return (char) skip();
        } nextChar {
            return (char) skip();
        } return (char) skip(); (char) skip() skip public class Main {

    static int visited[];
    static ArrayList<ArrayList<Integer>> adjlist;
    static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    }

    static class Graph{
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;
        int dist[];
        public Graph(int V){
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        }

        void addedge(int u, int v, int w ){
            adj.get(u).add(new edge(v,w));
            adj.get(v).add(new edge(u,w));
        }

        int dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }
            int dis = dist[2];

            return dis;
        }


    }



    static  int I[];
    static  int L[];
    static void LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }
        int lisLength = 1;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int houses[] = new int[m];
        for(int i=0; i<m; i++){
            houses[i] = sc.nextInt();
        }

        Arrays.sort(houses);
        int max = 0;
        for(int i=1; i<m; i++){
            max = Math.max(max,Math.abs(houses[i]-houses[i-1]));
        }
        max = Math.max(max,Math.abs((n+houses[0])-houses[m-1]));
        pw.println(n-max);
        pw.close();

    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    }
} public class Main {

    static int visited[];
    static ArrayList<ArrayList<Integer>> adjlist;
    static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    }

    static class Graph{
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;
        int dist[];
        public Graph(int V){
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        }

        void addedge(int u, int v, int w ){
            adj.get(u).add(new edge(v,w));
            adj.get(v).add(new edge(u,w));
        }

        int dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }
            int dis = dist[2];

            return dis;
        }


    }



    static  int I[];
    static  int L[];
    static void LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }
        int lisLength = 1;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int houses[] = new int[m];
        for(int i=0; i<m; i++){
            houses[i] = sc.nextInt();
        }

        Arrays.sort(houses);
        int max = 0;
        for(int i=1; i<m; i++){
            max = Math.max(max,Math.abs(houses[i]-houses[i-1]));
        }
        max = Math.max(max,Math.abs((n+houses[0])-houses[m-1]));
        pw.println(n-max);
        pw.close();

    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    }
} Main
import java.io. *;
import java.lang.reflect.Array;
import java.util.*;
import static java.lang.Math.*;
public class Main {

    static int visited[];
    static ArrayList<ArrayList<Integer>> adjlist;
    static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    }

    static class Graph{
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;
        int dist[];
        public Graph(int V){
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        }

        void addedge(int u, int v, int w ){
            adj.get(u).add(new edge(v,w));
            adj.get(v).add(new edge(u,w));
        }

        int dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }
            int dis = dist[2];

            return dis;
        }


    }



    static  int I[];
    static  int L[];
    static void LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }
        int lisLength = 1;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int houses[] = new int[m];
        for(int i=0; i<m; i++){
            houses[i] = sc.nextInt();
        }

        Arrays.sort(houses);
        int max = 0;
        for(int i=1; i<m; i++){
            max = Math.max(max,Math.abs(houses[i]-houses[i-1]));
        }
        max = Math.max(max,Math.abs((n+houses[0])-houses[m-1]));
        pw.println(n-max);
        pw.close();

    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    }
}
 
 
