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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct node {
  int v, w, to;
} edge[50005 * 20];
int pre[50005], cnt, dep[50005];
int S, T, z, head[50005], id;
int qq[50005], cur[50005];
void link(int u, int v, int w) {
  edge[cnt] = {v, w, head[u]};
  head[u] = cnt++;
  edge[cnt] = {u, 0, head[v]};
  head[v] = cnt++;
}
bool bfs() {
  for (int i = 0; i <= T; i++) dep[i] = 0;
  dep[S] = 1;
  int l = 0, r = 1;
  qq[r] = S;
  while (l < r) {
    int u = qq[++l];
    for (int i = head[u]; i != -1; i = edge[i].to) {
      int v = edge[i].v;
      if (!dep[v] && edge[i].w) dep[v] = dep[u] + 1, qq[++r] = v;
    }
  }
  return dep[T];
}
long long dfs(int u, long long mi) {
  long long res = 0;
  if (mi == 0 || u == T) return mi;
  for (int &i = cur[u]; i != -1; i = edge[i].to) {
    int v = edge[i].v;
    if (dep[u] + 1 == dep[v] && edge[i].w) {
      int minn = dfs(v, min(mi - res, 1ll * edge[i].w));
      edge[i].w -= minn;
      edge[i ^ 1].w += minn;
      res += minn;
      if (res == mi) return res;
    }
  }
  if (res == 0) dep[u] = 0;
  return res;
}
long long dinic() {
  long long res = 0;
  while (bfs()) {
    memcpy(cur, head, sizeof(head));
    res += dfs(S, 1e17);
  }
  return res;
}
int lowb(int x, int a[], int len) {
  return lower_bound(a + 1, a + len + 1, x) - a;
}
int n, m;
int xl[200], xr[200], cx[200], yl[200], yr[200], cy[200];
int main() {
  cin >> n >> m;
  for (int i = (1); i <= (m); i++)
    scanf("%d%d%d%d", &xl[i], &yl[i], &xr[i], &yr[i]),
        cx[i] = xl[i], cx[m + i] = xr[i] + 1, cy[i] = yl[i],
        cy[m + i] = yr[i] + 1;
  sort(cx + 1, cx + m * 2 + 1);
  sort(cy + 1, cy + m * 2 + 1);
  int xlen = unique(cx + 1, cx + m * 2 + 1) - (cx + 1);
  int ylen = unique(cy + 1, cy + m * 2 + 1) - (cy + 1);
  S = 0, T = xlen + ylen + 1;
  for (int i = (0); i <= (T); i++) head[i] = -1;
  for (int i = (1); i <= (xlen - 1); i++) link(S, i, cx[i + 1] - cx[i]);
  for (int i = (1); i <= (ylen - 1); i++) link(i + xlen, T, cy[i + 1] - cy[i]);
  for (int i = (1); i <= (m); i++) {
    int a = lowb(xl[i], cx, xlen), b = lowb(xr[i] + 1, cx, xlen),
        c = lowb(yl[i], cy, ylen), d = lowb(yr[i] + 1, cy, ylen);
    for (int x = (a); x <= (b - 1); x++)
      for (int y = (c); y <= (d - 1); y++) link(x, y + xlen, 0x3f3f3f3f);
  }
  printf("%lld\n", dinic());
  return 0;
}