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;
const int maxn = 555, maxm = 255555;
inline int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int n, xl[maxn], yl[maxn], xr[maxn], yr[maxn], xtmp[maxn], ytmp[maxn], xsz, ysz;
int s, t, el = 1, head[maxn], cur[maxn], to[maxm], nxt[maxm], flow[maxm];
int ans, q[maxn], h, r, dis[maxn];
inline void add(int u, int v, int f) {
  to[++el] = v;
  nxt[el] = head[u];
  head[u] = el;
  flow[el] = f;
  to[++el] = u;
  nxt[el] = head[v];
  head[v] = el;
  flow[el] = 0;
}
bool bfs() {
  memset(dis, -1, sizeof(dis));
  for (int i = (1); i <= (t); i++) cur[i] = head[i];
  dis[q[h = r = 1] = s] = 0;
  while (h <= r) {
    int u = q[h++];
    for (int i = head[u]; i; i = nxt[i]) {
      int v = to[i];
      if (flow[i] && dis[v] == -1) dis[q[++r] = v] = dis[u] + 1;
    }
  }
  return ~dis[t];
}
int dfs(int u, int minres) {
  if (u == t || !minres) return minres;
  int f, rtf = 0;
  for (int &i = cur[u]; i; i = nxt[i]) {
    int v = to[i];
    if (dis[v] == dis[u] + 1 && (f = dfs(v, min(minres, flow[i])))) {
      flow[i] -= f;
      flow[i ^ 1] += f;
      minres -= f;
      rtf += f;
      if (!minres) break;
    }
  }
  return rtf;
}
int main() {
  read();
  n = read();
  for (int i = (1); i <= (n); i++) {
    xl[i] = read();
    yl[i] = read();
    xr[i] = read() + 1, yr[i] = read() + 1;
    xtmp[2 * i - 1] = xl[i];
    xtmp[2 * i] = xr[i];
    ytmp[2 * i - 1] = yl[i];
    ytmp[2 * i] = yr[i];
  }
  sort(xtmp + 1, xtmp + 2 * n + 1);
  xsz = unique(xtmp + 1, xtmp + 2 * n + 1) - xtmp - 1;
  sort(ytmp + 1, ytmp + 2 * n + 1);
  ysz = unique(ytmp + 1, ytmp + 2 * n + 1) - ytmp - 1;
  for (int i = (1); i <= (xsz - 1); i++)
    for (int j = (1); j <= (ysz - 1); j++) {
      bool flag = false;
      for (int k = (1); k <= (n); k++)
        flag |= xl[k] <= xtmp[i] && xr[k] >= xtmp[i + 1] && yl[k] <= ytmp[j] &&
                yr[k] >= ytmp[j + 1];
      if (!flag) continue;
      add(i, j + xsz - 1, 2e9);
    }
  s = xsz + ysz - 1;
  t = xsz + ysz;
  for (int i = (1); i <= (xsz - 1); i++) add(s, i, xtmp[i + 1] - xtmp[i]);
  for (int i = (1); i <= (ysz - 1); i++)
    add(i + xsz - 1, t, ytmp[i + 1] - ytmp[i]);
  while (bfs()) ans += dfs(s, 2e9);
  printf("%d\n", ans);
}