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)));

    class E {
        int v;
        int c;
        int f;
        E(int v, int c) {
            this.v = v;
            this.c = c;
        }
    }

    List<Integer>[] g;
    List<E> edges = new ArrayList<>();
    int[] level;
    int[] que;
    int src, tgt;
    int inf = 1_000_000_000;

    void addEdge(int u, int v, int c, int rc) {
        g[u].add(edges.size());
        edges.add(new E(v, c));
        g[v].add(edges.size());
        edges.add(new E(u, rc));
    }

    boolean bfs() {
        Arrays.fill(level, -1);
        level[src] = 0;
        int a = 0, b = 0;
        que[b++] = src;
        while (a < b) {
            int u = que[a++];
            for (int i : g[u]) {
                E e = edges.get(i);
                int v = e.v;
                if (e.f < e.c && level[v] == -1) {
                    level[v] = level[u] + 1;
                    que[b++] = v;
                }
            }
        }
        return level[tgt] != -1;
    }

    int send(int u, int f) {
        if (u == tgt) return f;
        int sent = 0;
        for (int i : g[u]) {
            E e = edges.get(i);
            int v = e.v;
            if (level[v] == level[u] + 1) {
                int sf = Math.min(e.c - e.f, f);
                sf = send(v, sf);
                e.f += sf;
                E r = edges.get(i ^ 1);
                r.f -= sf;
                sent += sf;
                f -= sf;
                if (f == 0) break;
            }
        }
        return sent;
    }

    int flow() {
        int f = 0;
        while (bfs()) {
            int sf = send(src, inf);
            f += sf;
            if (sf == 0) break;
        }
        return f;
    }

    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(x1);
            ys.add(y);
            ys.add(y1);
        }
        List<Integer> wx = new ArrayList<>(), wy = new ArrayList<>();
        Map<Integer, Integer> mx = new HashMap<>(), my = new HashMap<>();
        int p = -1;
        for (int i : xs) {
            if (p != -1 && i - p > 1) wx.add(i - p - 1);
            wx.add(1);
            mx.put(i, wx.size() - 1);
            p = i;
        }
        p = -1;
        for (int i : ys) {
            if (p != -1 && i - p > 1) wy.add(i - p - 1);
            wy.add(1);
            my.put(i, wy.size() - 1);
            p = i;
        }
        int R = wx.size();
        int C = wy.size();
        g = new List[R+C+2];
        for (int i  = 0; i < g.length; i++) g[i] = new ArrayList<>();
        src = R + C;
        tgt = src + 1;
        level = new int[tgt+1];
        que = new int[tgt+1];
        for (int i = 0; i < R; i++) addEdge(src, i, wx.get(i), 0);
        for (int i = 0; i < C; i++) addEdge(R + i, tgt, wy.get(i), 0);
        for (int i = 0; i < R; i++)
            loop:
            for (int j = 0; j < C; j++)
                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]);
                    if ( a <= i && i <= x && b <= j && j <= y) {
                        addEdge(i, R + j, inf, 0);
                        continue loop;
                    }
                }
        int f = flow();
        writer.println(f);
    }

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