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:
// practice with rainboy
import java.io.*;
import java.util.*;

public class CF1198E extends PrintWriter {
	CF1198E() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1198E o = new CF1198E(); o.main(); o.flush();
	}

	static final int INF = 0x3f3f3f3f;
	int[] oo, oh; int __ = 1;
	int link(int o, int h) {
		oo[__] = o; oh[__] = h;
		return __++;
	}
	int[] ij, cc;
	int[] ae, qu, dd;
	int n_, m_;
	void init(int n, int m) {
		oo = new int[1 + m * 2]; oh = new int[1 + m * 2];
		ij = new int[m]; cc = new int[m * 2];
		ae = new int[n]; qu = new int[n]; dd = new int[n];
		n_ = n; m_ = 0;
	}
	void link_(int i, int j, int c) {
		int h = m_++;
		ij[h] = i ^ j;
		cc[h << 1] = c;
		ae[i] = link(ae[i], h << 1);
		ae[j] = link(ae[j], h << 1 | 1);
	}
	boolean bfs(int s, int t) {
		int head = 0, cnt = 0;
		Arrays.fill(dd, n_);
		dd[s] = 0; qu[head + cnt++] = s;
		while (cnt > 0) {
			int i = qu[head++]; cnt--;
			int d = dd[i] + 1;
			for (int o = ae[i]; o != 0; o = oo[o]) {
				int h_ = oh[o];
				if (cc[h_] > 0) {
					int h = h_ >> 1;
					int j = i ^ ij[h];
					if (dd[j] > d) {
						dd[j] = d;
						if (j == t)
							return true;
						qu[head + cnt++] = j;
					}
				}
			}
		}
		return false;
	}
	int dfs(int i, int t, int c) {
		if (i == t)
			return c;
		int d = dd[i] + 1;
		for (int o = ae[i]; o != 0; o = oo[o]) {
			int h_ = oh[o];
			if (cc[h_] > 0) {
				int h = h_ >> 1;
				int j = i ^ ij[h];
				if (dd[j] == d) {
					int f = dfs(j, t, Math.min(c, cc[h_]));
					if (f > 0) {
						cc[h_] -= f; cc[h_ ^ 1] += f;
						return f;
					}
				}
			}
		}
		dd[i] = n_;
		return 0;
	}
	int dinic(int s, int t) {
		int sum = 0, f;
		while (bfs(s, t))
			while ((f = dfs(s, t, INF)) != 0)
				sum += f;
		return sum;
	}
	int compress(int[] xx, Integer[] hh, int[] xx_, int n) {
		Arrays.sort(hh, (i, j) -> xx[i] - xx[j]);
		int i = 0;
		for (int h = 0; h < n; h++)
			if (h + 1 == n || xx[hh[h + 1]] != xx[hh[h]]) {
				xx_[i] = xx[hh[h]];
				xx[hh[h]] = i++;
			} else
				xx[hh[h]] = i;
		return i;
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		if (m == 0) {
			println(0);
			return;
		}
		int[] xx = new int[m * 2];
		int[] yy = new int[m * 2];
		int[] xx_ = new int[m * 2];
		int[] yy_ = new int[m * 2];
		for (int h = 0; h < m; h++) {
			int l = h << 1, r = h << 1 | 1;
			xx[l] = sc.nextInt();
			yy[l] = sc.nextInt();
			xx[r] = sc.nextInt() + 1;
			yy[r] = sc.nextInt() + 1;
		}
		Integer[] hh = new Integer[m * 2];
		for (int h = 0; h < m * 2; h++)
			hh[h] = h;
		int nx = compress(xx, hh, xx_, m * 2) - 1;
		int ny = compress(yy, hh, yy_, m * 2) - 1;
		boolean[][] used = new boolean[nx][ny];
		for (int h = 0; h < m; h++) {
			int l = h << 1, r = h << 1 | 1;
			for (int i = xx[l]; i < xx[r]; i++)
				for (int j = yy[l]; j < yy[r]; j++)
					used[i][j] = true;
		}
		init(nx + ny + 2, nx * ny + nx + ny);
		int s = nx + ny, t = s + 1;
		for (int i = 0; i < nx; i++)
			for (int j = 0; j < ny; j++)
				if (used[i][j])
					link_(i, nx + j, INF);
		for (int i = 0; i < nx; i++)
			link_(s, i, xx_[i + 1] - xx_[i]);
		for (int j = 0; j < ny; j++)
			link_(nx + j, t, yy_[j + 1] - yy_[j]);
		println(dinic(s, t));
	}
}