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>
const long long Inf = 0x7fffffffffffffff;
namespace Dinic {
const int MN = 205, MM = 10005;
int N, S, T;
int h[MN], iter[MN], nxt[MM * 2], to[MM * 2], tot;
long long w[MM * 2];
inline void Init(int _N) {
  N = _N, tot = 1;
  for (int i = 1; i <= N; ++i) h[i] = 0;
}
inline void SetST(int _S, int _T) { S = _S, T = _T; }
inline void ins(int u, int v, long long x) {
  nxt[++tot] = h[u], to[tot] = v, w[tot] = x, h[u] = tot;
}
inline void insw(int u, int v, long long w1, long long w2 = 0) {
  if (!u) u = S;
  if (!v) v = T;
  ins(u, v, w1), ins(v, u, w2);
}
int lv[MN], que[MN], l, r;
inline bool Lvl() {
  for (int i = 1; i <= N; ++i) lv[i] = 0;
  lv[S] = 1;
  que[l = r = 1] = S;
  while (l <= r) {
    int u = que[l++];
    for (int i = h[u]; i; i = nxt[i])
      if (w[i] && !lv[to[i]]) {
        lv[to[i]] = lv[u] + 1;
        que[++r] = to[i];
      }
  }
  return lv[T] != 0;
}
long long Flow(int u, long long f) {
  if (u == T) return f;
  long long d = 0, s = 0;
  for (int &i = iter[u]; i; i = nxt[i])
    if (w[i] && lv[to[i]] == lv[u] + 1) {
      d = Flow(to[i], std::min(f, w[i]));
      f -= d, s += d;
      w[i] -= d, w[i ^ 1] += d;
      if (!f) break;
    }
  return s;
}
inline long long Dinic() {
  long long Ans = 0;
  while (Lvl()) {
    for (int i = 1; i <= N; ++i) iter[i] = h[i];
    Ans += Flow(S, Inf);
  }
  return Ans;
}
}  // namespace Dinic
const int MM = 51, MS = 105;
int M, sx[MM], sy[MM], tx[MM], ty[MM];
int dx[MS], dy[MS], cx, cy;
int V[MS][MS];
int main() {
  scanf("%*d%d", &M);
  for (int i = 1; i <= M; ++i)
    scanf("%d%d%d%d", &sx[i], &sy[i], &tx[i], &ty[i]),
        dx[++cx] = sx[i], dx[++cx] = tx[i] + 1, dy[++cy] = sy[i],
        dy[++cy] = ty[i] + 1;
  std::sort(dx + 1, dx + cx + 1);
  std::sort(dy + 1, dy + cy + 1);
  cx = std::unique(dx + 1, dx + cx + 1) - dx - 1;
  cy = std::unique(dy + 1, dy + cy + 1) - dy - 1;
  Dinic::Init(cx + cy), Dinic::SetST(cx + cy - 1, cx + cy);
  for (int j = 1; j < cx; ++j) Dinic::insw(0, j, dx[j + 1] - dx[j]);
  for (int j = 1; j < cy; ++j) Dinic::insw(cx - 1 + j, 0, dy[j + 1] - dy[j]);
  for (int i = 1; i <= M; ++i) {
    int lx, rx, ly, ry;
    lx = std::lower_bound(dx + 1, dx + cx + 1, sx[i]) - dx;
    rx = std::lower_bound(dx + 1, dx + cx + 1, tx[i] + 1) - dx - 1;
    ly = std::lower_bound(dy + 1, dy + cy + 1, sy[i]) - dy;
    ry = std::lower_bound(dy + 1, dy + cy + 1, ty[i] + 1) - dy - 1;
    for (int j = lx; j <= rx; ++j)
      for (int k = ly; k <= ry; ++k) V[j][k] = 1;
  }
  for (int j = 1; j < cx; ++j)
    for (int k = 1; k < cy; ++k)
      if (V[j][k]) Dinic::insw(j, cx - 1 + k, Inf);
  printf("%lld\n", Dinic::Dinic());
  return 0;
}