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.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintStream;
import java.util.*;

public class CF_1198E {
    public static void main(String args[]) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));
        PrintStream out = new PrintStream(new BufferedOutputStream(System.out));

        int n = in.nextInt(), m = in.nextInt();
        ArrayList<int[]> rects = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            rects.add(new int[]{in.nextInt(), in.nextInt(), in.nextInt() + 1, in.nextInt() + 1});
        }

        if(m == 0){
            out.println(0);
            
            out.close();
            in.close();
            return;
        }

        ArrayList<Integer> xs = new ArrayList<>();
        ArrayList<Integer> ys = new ArrayList<>();

        for (int[] rect : rects) {
            xs.add(rect[0]);
            xs.add(rect[2]);

            ys.add(rect[1]);
            ys.add(rect[3]);
        }

        xs = new ArrayList<>(new HashSet<>(xs));
        ys = new ArrayList<>(new HashSet<>(ys));
        Collections.shuffle(xs);
        Collections.shuffle(ys);
        Collections.sort(xs);
        Collections.sort(ys);


        boolean[][] cov = new boolean[xs.size() - 1][ys.size() - 1];
        for (int[] rect : rects) {
            for (int i = 0; i < cov.length; i++) {
                if (xs.get(i) < rect[0] || rect[2] <= xs.get(i)) continue;

                for (int j = 0; j < cov[0].length; j++) {
                    if (ys.get(j) < rect[1] || rect[3] <= ys.get(j)) continue;
                    cov[i][j] = true;
                }
            }
        }

        Dinic.init(cov.length + cov[0].length);
        for (int i = 0; i < cov.length; i++) {
            for (int j = 0; j < cov[0].length; j++) {
                if (cov[i][j]) {
                    Dinic.add(i, j + cov.length, Long.MAX_VALUE);
                }
            }
        }

        for (int i = 0; i < cov.length; i++) {
            Dinic.add(Dinic.s, i, xs.get(i + 1) - xs.get(i));
        }
        for(int i = 0; i < cov[0].length; i++){
            Dinic.add(i + cov.length, Dinic.t, ys.get(i + 1) - ys.get(i));
        }

        out.println(Dinic.ans());




        out.close();
        in.close();
    }

    static class Dinic {
        static class Edge {
            int u, v;
            long flow, cap;
            Edge rev;

            Edge(int u, int v, long flow, long cap) {
                this.u = u;
                this.v = v;
                this.flow = flow;
                this.cap = cap;
            }
        }

        static int n;
        static int s, t;

        static int[] ptr;
        static int[] levels;
        static ArrayDeque<Integer> q;

        static ArrayList<ArrayList<Edge>> adj;

        static void init(int n) {
            n = n;
            s = n++;
            t = n++;

            ptr = new int[n];
            levels = new int[n];

            q = new ArrayDeque<>();
            adj = new ArrayList<>();
            for (int i = 0; i < n; i++) adj.add(new ArrayList<>());
        }

        static void add(int u, int v, long cap) {
            Edge a = new Edge(u, v, 0, cap);
            Edge b = new Edge(v, u, 0, 0);

            a.rev = b;
            b.rev = a;

            adj.get(u).add(a);
            adj.get(v).add(b);
        }

        static boolean bfs() {
            Arrays.fill(levels, -1);
            levels[s] = 0;
            q.add(s);

            while (!q.isEmpty()) {
                int curr = q.poll();
                for (Edge e : adj.get(curr)) {
                    if (levels[e.v] == -1 && e.flow < e.cap) {
                        levels[e.v] = levels[curr] + 1;

                        q.add(e.v);
                    }
                }
            }
            return levels[t] != -1;
        }

        static long dfs(int curr, long min) {
            if (min == 0) return 0;
            if (curr == t) return min;

            for (; ptr[curr] < adj.get(curr).size(); ptr[curr]++) {
                Edge e = adj.get(curr).get(ptr[curr]);
                if (levels[e.u] + 1 != levels[e.v] || e.flow >= e.cap) continue;

                long ret = dfs(e.v, Math.min(min, e.cap - e.flow));
                if(ret == 0) continue;

                e.flow += ret;
                e.rev.flow -= ret;
                return ret;
            }
            return 0;
        }

        static long ans() {
            long ret = 0;
            while (bfs()) {
                long curr;

                Arrays.fill(ptr, 0);
                while ((curr = dfs(s, Long.MAX_VALUE)) != 0) {
                    ret += curr;
                }
            }
            return ret;
        }

    }


}