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.*;
import java.util.*;

public class Test {

    static int readInt() {
        int ans = 0;
        boolean neg = false;
        try {
            boolean start = false;
            for (int c = 0; (c = System.in.read()) != -1; ) {
                if (c == '-') {
                    start = true;
                    neg = true;
                    continue;
                } else if (c >= '0' && c <= '9') {
                    start = true;
                    ans = ans * 10 + c - '0';
                } else if (start) break;
            }
        } catch (IOException e) {
        }
        return neg ? -ans : ans;
    }

    static long readLong() {
        long ans = 0;
        boolean neg = false;
        try {
            boolean start = false;
            for (int c = 0; (c = System.in.read()) != -1; ) {
                if (c == '-') {
                    start = true;
                    neg = true;
                    continue;
                } else if (c >= '0' && c <= '9') {
                    start = true;
                    ans = ans * 10 + c - '0';
                } else if (start) break;
            }
        } catch (IOException e) {
        }
        return neg ? -ans : ans;
    }

    static String readLine() {
        StringBuilder b = new StringBuilder();
        try {
            boolean start = false;
            for (int c = 0; (c = System.in.read()) != -1; ) {
                if (c != '\r' && c != '\n') {
                    start = true;
                    b.append((char)c);
                } else if (start) break;
            }
        } catch (IOException e) {
        }
        return b.toString();
    }

    static PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    int R, C;
    boolean[][] blacks;
    int[] row, col, hei, wid;
    boolean[] urow, ucol;
    int best = Integer.MAX_VALUE;

    void go(int used) {
        if (used >= best) return;
        int r = 0, c = 0;
        loopr:
        for (int i = 0; i < R; i++)
            if (!urow[i])
                for (int j = 0; j < C; j++)
                    if (!ucol[j] && blacks[i][j]) {
                        r += hei[i];
                        continue loopr;
                    }
        loopc:
        for (int j = 0; j < C; j++)
            if (!ucol[j])
                for (int i = 0; i < R; i++)
                    if (!urow[i] && blacks[i][j]) {
                        c += wid[j];
                        continue loopc;
                    }
        int ans = Math.min(r, c) + used;
        best = Math.min(ans, best);
        if (r == 1 || c == 1) return;
        int mr = -1, bestw = -1;
        for (int i = 0; i < R; i++)
            if (!urow[i]) {
                int w = 0;
                for (int j = 0; j < C; j++)
                    if (!ucol[j] && blacks[i][j]) w += wid[j];
                if (w > bestw) {
                    mr = i;
                    bestw = w;
                }
            }
        int mc = 0, besth = -1;
        for (int j = 0; j < C; j++)
            if (!ucol[j]) {
                int h = 0;
                for (int i = 0; i < R; i++)
                    if (!urow[i] && blacks[i][j]) h += hei[i];
                if (h > besth) {
                    besth = h;
                    mc = j;
                }
            }

        if (used + bestw >= best && used + hei[mr] < best ) {
            urow[mr] = true;
            go(used + hei[mr]);
            urow[mr] = false;
            return;
        }
        if (used + besth >= best && used + wid[mc] < best) {
            ucol[mc] = true;
            go(used + wid[mc]);
            ucol[mc] = false;
            return;
        }

        urow[mr] = true;
        go(used + hei[mr]);
        urow[mr] = false;

        List<Integer> js = new ArrayList<>();
        int w = 0;
        for (int j = 0; j < C; j++)
            if (!ucol[j] && blacks[mr][j]) {
                ucol[j] = true;
                js.add(j);
                w += wid[j];
            }
        go(used + w);
        for (int j : js) ucol[j] = false;
    }

    void start() {
        int n = readInt(), m = readInt();
        if (m == 0) {
            writer.println(0);
            return;
        }
        List<int[]> rects = new ArrayList<>();
        Set<Integer> xs = new TreeSet<>(), ys = new TreeSet<>();
        for (int i = 0; i < m; i++) {
            int x = readInt(), y = readInt(), x1 = readInt(), y1 = readInt();
            x--;
            y--;
            rects.add(new int[]{x, y, x1, y1});
            xs.add(x);
            xs.add(x1);
            ys.add(y);
            ys.add(y1);
        }
        xs.add(0);
        xs.add(n);
        ys.add(0);
        ys.add(n);
        List<Integer> xa = new ArrayList<>(xs), ya = new ArrayList<>(ys);
        R = xa.size() - 1;
        C = ya.size() - 1;
        hei = new int[R];
        wid = new int[C];
        for (int i = 0; i < R; i++) hei[i] = xa.get(i+1) - xa.get(i);
        for (int i = 0; i < C; i++) wid[i] = ya.get(i+1) - ya.get(i);
        row = new int[R];
        col = new int[C];
        urow = new boolean[R];
        ucol = new boolean[C];
        blacks  = new boolean[R][C];
        for (int i = 0; i < R; i++)
            loop:
            for (int j = 0; j < C; j++)
                for (int[] r : rects) {
                    if (r[0] <= xa.get(i) && xa.get(i+1) <= r[2] && r[1] <= ya.get(j) && ya.get(j+1) <= r[3]) {
                        blacks[i][j] = true;
                        row[i] += wid[j];
                        col[j] += hei[i];
                    }
        }
        go(0);
        writer.println(best);
    }

    public static void main(String[] args) {
        Test te = new Test();
        te.start();
        writer.flush();
    }
}