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.Collection;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Queue;
import java.util.LinkedList;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class TaskE {
        final long INF = 1L << 40;
        ArrayList<Vertex> vs = new ArrayList<>();

        void addEdge(Vertex a, Vertex b, long cap) {
            Edge e = new Edge(a, b, cap);
            Edge eRev = new Edge(b, a, 0);
            e.rev = eRev;
            eRev.rev = e;
            a.adj.add(e);
            b.adj.add(eRev);
        }

        long augment(Vertex source, Vertex sink) {
            for (Vertex v : vs) v.mark = false;

            Queue<Vertex> Q = new LinkedList<>();
            Q.add(source);
            while (!Q.isEmpty()) {
                Vertex cur = Q.poll();
                for (Edge e : cur.adj) {
                    if (e.flow > 0 && e.dist.mark == false) {
                        e.dist.parent = e;
                        e.dist.mark = true;
                        Q.add(e.dist);
                    }
                }
            }
            if (sink.mark == false) return 0;
            long bottleneck = INF;
            Vertex cur = sink;
            while (true) {
                Vertex a = cur.parent.src;
                bottleneck = Math.min(bottleneck, cur.parent.flow);
                if (a == source)
                    break;
                cur = a;
            }
            cur = sink;
            while (true) {
                Vertex a = cur.parent.src;
                cur.parent.flow -= bottleneck;
                cur.parent.rev.flow += bottleneck;
                if (a == source)
                    break;
                cur = a;
            }
            return bottleneck;
        }

        long maxFlow(Vertex source, Vertex sink) {
            long x;
            long res = 0;
            while ((x = augment(source, sink)) > 0) {
                res += x;
            }
            return res;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            ArrayList<Integer> xs = new ArrayList<>();
            ArrayList<Integer> ys = new ArrayList<>();

            int[][] coord = new int[m][];
            for (int i = 0; i < m; i++) {
                int x1 = in.nextInt() - 1;
                int y1 = in.nextInt() - 1;
                int x2 = in.nextInt();
                int y2 = in.nextInt();
                xs.add(x1);
                xs.add(x2);
                ys.add(y1);
                ys.add(y2);
                coord[i] = new int[]{x1, x2, y1, y2};
            }
            Collections.sort(xs);
            Collections.sort(ys);

            Vertex source = new Vertex();
            Vertex sink = new Vertex();

            ArrayList<Vertex> left = new ArrayList<>();
            for (int i = 0; i < xs.size() - 1; i++) {
                Vertex v = new Vertex();
                addEdge(source, v, xs.get(i + 1) - xs.get(i));
                left.add(v);
            }
            ArrayList<Vertex> right = new ArrayList<>();
            for (int i = 0; i < ys.size() - 1; i++) {
                Vertex v = new Vertex();
                addEdge(v, sink, ys.get(i + 1) - ys.get(i));
                right.add(v);
            }

            Vertex[] mid = new Vertex[m];
            for (int i = 0; i < m; i++) {
                mid[i] = new Vertex();
            }
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < xs.size() - 1; j++) {
                    if (coord[i][0] <= xs.get(j) && xs.get(j + 1) <= coord[i][1])
                        addEdge(left.get(j), mid[i], INF);
                }
                for (int j = 0; j < ys.size() - 1; j++) {
                    if (coord[i][2] <= ys.get(j) && ys.get(j + 1) <= coord[i][3])
                        addEdge(mid[i], right.get(j), INF);
                }
            }
            long ans = maxFlow(source, sink);
            out.println(ans);
        }

        class Edge {
            Vertex dist;
            Vertex src;
            long flow;
            Edge rev;

            Edge(Vertex _src, Vertex _dist, long _flow) {
                this.src = _src;
                this.dist = _dist;
                this.flow = _flow;
            }

        }

        class Vertex {
            boolean mark;
            Edge parent;
            ArrayList<Edge> adj = new ArrayList<>();

            Vertex() {
                vs.add(this);
            }

        }

    }

    static class InputReader {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputStream stream;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isWhitespace(c));
            return res * sgn;
        }

    }
}