Problem: There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs min(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost.

The square is large, so we give it to you in a compressed way. The set of black cells is the union of m rectangles.

Input

The first line contains two integers n and m (1 ≤ n ≤ 10^{9}, 0 ≤ m ≤ 50) — the size of the square grid and the number of black rectangles.

Each of the next m lines contains 4 integers x_{i1} y_{i1} x_{i2} y_{i2} (1 ≤ x_{i1} ≤ x_{i2} ≤ n, 1 ≤ y_{i1} ≤ y_{i2} ≤ n) — the coordinates of the bottom-left and the top-right corner cells of the i-th black rectangle.

The rectangles may intersect.

Output

Print a single integer — the minimum total cost of painting the whole square in white.

Examples

Input


10 2
4 1 5 10
1 4 10 5


Output


4


Input


7 6
2 1 2 1
4 2 4 3
2 5 2 5
2 3 5 3
1 2 1 2
3 2 5 3


Output


3

Note

The examples and some of optimal solutions are shown on the pictures below.

<image>

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.SortedSet;
import java.util.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] rx1 = new int[m];
            int[] ry1 = new int[m];
            int[] rx2 = new int[m];
            int[] ry2 = new int[m];
            SortedSet<Integer> xSet = new TreeSet<>();
            SortedSet<Integer> ySet = new TreeSet<>();
            for (int i = 0; i < m; i++) {
                rx1[i] = in.nextInt();
                ry1[i] = in.nextInt();
                rx2[i] = in.nextInt() + 1;
                ry2[i] = in.nextInt() + 1;
                xSet.add(rx1[i]);
                xSet.add(rx2[i]);
                ySet.add(ry1[i]);
                ySet.add(ry2[i]);
            }

            int[] allX = new int[xSet.size()];
            int p = 0;
            for (int x : xSet) {
                allX[p++] = x;
            }

            int[] allY = new int[ySet.size()];
            p = 0;
            for (int y : ySet) {
                allY[p++] = y;
            }

            int sizeX = allX.length;
            int sizeY = allY.length;
            boolean[][] s = new boolean[sizeX][sizeY];
            for (int i = 0; i < m; i++) {
                int cx1 = Arrays.binarySearch(allX, rx1[i]);
                int cx2 = Arrays.binarySearch(allX, rx2[i]);
                int cy1 = Arrays.binarySearch(allY, ry1[i]);
                int cy2 = Arrays.binarySearch(allY, ry2[i]);
                for (int x = cx1; x < cx2; x++) {
                    for (int y = cy1; y < cy2; y++) {
                        s[x][y] = true;
                    }
                }
            }

            Graph g = new Graph(sizeX + sizeY + 2);
            for (int x = 0; x + 1 < sizeX; x++) {
                g.addEdge(g.s, x, allX[x + 1] - allX[x]);
            }
            for (int y = 0; y + 1 < sizeY; y++) {
                g.addEdge(sizeX + y, g.t, allY[y + 1] - allY[y]);
            }
            for (int x = 0; x < sizeX; x++) {
                for (int y = 0; y < sizeY; y++) {
                    if (s[x][y]) {
                        g.addEdge(x, sizeX + y, g.infinity);
                    }
                }
            }
            out.println(g.minCut());
        }

        class Graph {
            final long infinity = (long) 1e12;
            int n;
            int s;
            int t;
            int[] firstEdge;
            int[] nextEdge;
            int[] edgeDst;
            long[] edgeCap;
            long[] edgeFlow;
            int numEdges;
            int[] level;
            int[] q;
            int[] lastEdge;

            Graph(int n) {
                this.n = n;
                s = n - 1;
                t = n - 2;
                firstEdge = new int[n];
                final int initialEdges = 10;
                nextEdge = new int[initialEdges];
                edgeDst = new int[initialEdges];
                edgeCap = new long[initialEdges];
                edgeFlow = new long[initialEdges];
                numEdges = 0;
                level = new int[n];
                q = new int[n];
                lastEdge = new int[n];
                Arrays.fill(firstEdge, -1);
            }

            void reallocate() {
                int k = nextEdge.length * 3 / 2 + 1;
                nextEdge = Arrays.copyOf(nextEdge, k);
                edgeDst = Arrays.copyOf(edgeDst, k);
                edgeCap = Arrays.copyOf(edgeCap, k);
                edgeFlow = Arrays.copyOf(edgeFlow, k);
            }

            void addEdge(int a, int b, long cap) {
                if (numEdges + 2 >= nextEdge.length) {
                    reallocate();
                }
                int e = numEdges++;
                nextEdge[e] = firstEdge[a];
                firstEdge[a] = e;
                edgeDst[e] = b;
                edgeCap[e] = cap;
                edgeFlow[e] = 0;

                e = numEdges++;
                nextEdge[e] = firstEdge[b];
                firstEdge[b] = e;
                edgeDst[e] = a;
                edgeCap[e] = 0;
                edgeFlow[e] = 0;
            }

            long minCut() {
                return maxFlow();
            }

            long maxFlow() {
                long flow = 0;
                while (bfs()) {
                    for (int i = 0; i < n; i++) {
                        lastEdge[i] = firstEdge[i];
                    }
                    while (true) {
                        long add = dfs(s, infinity);
                        if (add == 0) {
                            break;
                        }
                        flow += add;
                    }
                }
                return flow;
            }

            long dfs(int v, long delta) {
                if (v == t) {
                    return delta;
                }
                for (; lastEdge[v] >= 0; lastEdge[v] = nextEdge[lastEdge[v]]) {
                    int e = lastEdge[v];
                    int u = edgeDst[e];
                    if (level[u] != level[v] + 1) {
                        continue;
                    }
                    long x = Math.min(delta, edgeCap[e] - edgeFlow[e]);
                    if (x <= 0) {
                        continue;
                    }
                    x = dfs(u, x);
                    if (x > 0) {
                        edgeFlow[e] += x;
                        edgeFlow[e ^ 1] -= x;
                        return x;
                    }
                }
                level[v] = -1;
                return 0;
            }

            boolean bfs() {
                Arrays.fill(level, -1);
                q[0] = s;
                level[s] = 0;
                int qt = 0;
                int qh = 1;
                while (qt < qh) {
                    int v = q[qt++];
                    for (int e = firstEdge[v]; e >= 0; e = nextEdge[e]) {
                        int u = edgeDst[e];
                        if (edgeFlow[e] < edgeCap[e] && level[u] < 0) {
                            level[u] = level[v] + 1;
                            q[qh++] = u;
                        }
                    }
                }
                return level[t] >= 0;
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}