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[1001000 * 2];
int pre[1001000], cnt, dep[1001000], S, T, z, head[1001000], sum, id;
int n, m, q[1001000], cur[1001000], lsx[999], lsy[999], idx, idy, aa[999],
    bb[999], cc[999], dd[999];
void add(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;
  q[r] = S;
  while (l < r) {
    int u = q[++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, q[++r] = v;
    }
  }
  return dep[T];
}
int dfs(int u, int mi) {
  int 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, 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;
}
int dinic() {
  int res = 0;
  while (bfs()) {
    memcpy(cur, head, sizeof(head));
    res += dfs(S, 0x3f3f3f3f);
  }
  return res;
}
int getlow(int a[], int len, int x) {
  return lower_bound(a + 1, a + 1 + len, x) - a;
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &aa[i], &bb[i], &cc[i], &dd[i]);
    lsx[++idx] = aa[i];
    lsx[++idx] = cc[i] + 1;
    lsy[++idy] = bb[i];
    lsy[++idy] = dd[i] + 1;
  }
  sort(lsx + 1, lsx + 1 + idx);
  sort(lsy + 1, lsy + 1 + idy);
  T = idx + idy + 2;
  idx = unique(lsx + 1, lsx + 1 + idx) - (lsx + 1);
  idy = unique(lsy + 1, lsy + 1 + idy) - (lsy + 1);
  for (int i = 1; i < idx; i++) add(S, i, lsx[i + 1] - lsx[i]);
  for (int i = 1; i < idy; i++) add(idx + i, T, lsy[i + 1] - lsy[i]);
  for (int i = 1; i <= m; i++) {
    int id1 = getlow(lsx, idx, aa[i]);
    int id2 = getlow(lsx, idx, cc[i] + 1);
    int id3 = getlow(lsy, idy, bb[i]);
    int id4 = getlow(lsy, idy, dd[i] + 1);
    for (int xx = id1; xx <= id2 - 1; xx++)
      for (int yy = id3; yy <= id4 - 1; yy++) add(xx, yy + idx, 1e8 + 5);
  }
  printf("%d\n", dinic());
  return 0;
}