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;
    int[][] blacks;
    int[] row, col, hei, wid;
    int best = Integer.MAX_VALUE;

    void go(int used) {
        if (used >= best) return;
        int r = 0, c = 0;
        for (int i = 0; i < R; i++) if (row[i] != 0) r += hei[i];
        for (int i = 0; i < C; i++) if (col[i] != 0) c += wid[i];
        int ans = Math.min(r, c) + used;
        best = Math.min(ans, best);
        if (r == 1 || c == 1) return;
        int mr = 0;
        for (int i = 0; i < R; i++) if (row[i] > row[mr]) mr = i;
        int mc = 0;
        for (int i = 0; i < C; i++) if (col[i] > col[mc]) mc = i;

        if (used + row[mr] >= best && used + hei[mr] < best ) {
            for (int i = 0; i < C; i++) if (blacks[mr][i] != 0) col[i] -= hei[mr];
            int[] ta = Arrays.copyOf(blacks[mr], C);
            Arrays.fill(blacks[mr], 0);
            int t = row[mr];
            row[mr] = 0;
            go(used + hei[mr]);
            row[mr] = t;
            System.arraycopy(ta, 0, blacks[mr], 0, C);
            for (int i = 0; i < C; i++) if (blacks[mr][i] != 0) col[i] += hei[mr];
            return;
        }
        if (used + col[mc] >= best && used + wid[mc] < best) {
            for (int i = 0; i < R; i++) if (blacks[i][mc] != 0) row[i] -= wid[mc];
            int[] ta = new int[R];
            for (int i = 0; i < R; i++) {
                ta[i] = blacks[i][mc];
                blacks[i][mc] = 0;
            }
            int t = col[mc];
            col[mc] = 0;
            go(used + wid[mc]);
            col[mc] = t;
            for (int i = 0; i < R; i++) blacks[i][mc] = ta[i];
            for (int i = 0; i < R; i++) if (blacks[i][mc] != 0) row[i] += wid[mc];
            return;
        }

        for (int i = 0; i < C; i++) if (blacks[mr][i] != 0) col[i] -= hei[mr];
        int[] ta = Arrays.copyOf(blacks[mr], C);
        Arrays.fill(blacks[mr], 0);
        int t = row[mr];
        row[mr] = 0;
        go(used + hei[mr]);
        row[mr] = t;
        System.arraycopy(ta, 0, blacks[mr], 0, C);
        for (int i = 0; i < C; i++) if (blacks[mr][i] != 0) col[i] += hei[mr];

        for (int i = 0; i < R; i++) if (blacks[i][mc] != 0) row[i] -= wid[mc];
        ta = new int[R];
        for (int i = 0; i < R; i++) {
            ta[i] = blacks[i][mc];
            blacks[i][mc] = 0;
        }
        t = col[mc];
        col[mc] = 0;
        go(used + wid[mc]);
        col[mc] = t;
        for (int i = 0; i < R; i++) blacks[i][mc] = ta[i];
        for (int i = 0; i < R; i++) if (blacks[i][mc] != 0) row[i] += wid[mc];
    }

    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();
            rects.add(new int[]{x, y, x1, y1});
            xs.add(x);
            xs.add(x+1);
            xs.add(x1);
            xs.add(x1+1);
            ys.add(y);
            ys.add(y+1);
            ys.add(y1);
            ys.add(y1+1);
        }
        R = xs.size();
        C = ys.size();
        Map<Integer, Integer> mx = new HashMap<>(), my = new HashMap<>(), rx = new HashMap<>(), ry = new HashMap<>();
        int no = 0;
        for (int x : xs) {
            mx.put(x, no);
            rx.put(no, x);
            no++;
        }
        no = 0;
        for (int y : ys) {
            my.put(y, no);
            ry.put(no, y);
            no++;
        }
        hei = new int[R];
        wid = new int[C];
        for (int i = 0; i + 1 < R; i++) {
            hei[i] = rx.get(i+1) - rx.get(i);
        }
        hei[R-1] = 1;
        for (int i = 0; i + 1 < C; i++) {
            wid[i] = ry.get(i+1) - ry.get(i);
        }
        wid[C-1] = 1;

        R = xs.size();
        C = ys.size();
        row = new int[R];
        col = new int[C];
        blacks  = new int[R][C];
        for (int[] r : rects) {
            int a = mx.get(r[0]), b = my.get(r[1]), x = mx.get(r[2]), y = my.get(r[3]);
            for (int i = a; i <= x; i++)
                for (int j = b; j <= y; j++)
                    if (blacks[i][j] == 0) {
                        blacks[i][j] = 1;
                        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();
    }
}