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>
int N, u[50], d[50], l[50], r[50], Hx[102], Hy[102], Lx, Ly;
template <int xn, int xe>
struct flow {
  int head[xn], next[xe], to[xe], fl[xe], N, E, dep[xn], q[xn + 1];
  inline void add(int u, int v, int f) {
    next[E] = head[u], to[E] = v, fl[E] = f, head[u] = E++;
    next[E] = head[v], to[E] = u, fl[E] = 0, head[v] = E++;
  }
  void clear(int n) {
    N = n, E = 0;
    for (int i = 0; i < N; i++) head[i] = -1;
  }
  bool BFS() {
    for (int i = 0; i < N; i++) dep[i] = 0;
    dep[0] = 1;
    q[1] = 0;
    int H = 0, T = 1, u;
    while (H < T)
      for (int e = head[u = q[++H]]; ~e; e = next[e])
        if (fl[e] && !dep[to[e]]) {
          dep[q[++T] = to[e]] = dep[u] + 1;
          if (to[e] == N - 1) return true;
        }
    return false;
  }
  int DINIC(int p, int f) {
    if (p == N - 1) return f;
    int u = 0, y;
    for (int e = head[p]; ~e; e = next[e])
      if (fl[e] && dep[to[e]] == dep[p] + 1 &&
          (y = DINIC(to[e], std::min(f, fl[e])))) {
        u += y;
        f -= y;
        fl[e] -= y;
        fl[e ^ 1] += y;
        if (f == 0) return u;
      }
    if (u == 0) dep[p] = 0;
    return u;
  }
  int operator()() {
    int O = 0;
    while (BFS()) O += DINIC(0, 1000000000);
    return O;
  }
};
flow<666, 233333> G;
int main() {
  scanf("%*d%d", &N);
  if (N == 0) {
    puts("0");
    return 0;
  }
  for (int i = 0; i < N; i++) {
    scanf("%d%d%d%d", u + i, l + i, d + i, r + i);
    Hx[Lx++] = --u[i];
    Hx[Lx++] = d[i];
    Hy[Ly++] = --l[i];
    Hy[Ly++] = r[i];
  }
  std::sort(Hx, Hx + Lx);
  Lx = std::unique(Hx, Hx + Lx) - Hx;
  std::sort(Hy, Hy + Ly);
  Ly = std::unique(Hy, Hy + Ly) - Hy;
  G.clear(1 + (Lx - 1) + (Ly - 1) + N + 1);
  for (int i = 1; i < Lx; i++) G.add(0, i, Hx[i] - Hx[i - 1]);
  for (int i = 1; i < Ly; i++) G.add(Lx - 1 + i, G.N - 1, Hy[i] - Hy[i - 1]);
  for (int i = 0; i < N; i++) {
    u[i] = std::lower_bound(Hx, Hx + Lx, u[i]) - Hx;
    d[i] = std::lower_bound(Hx, Hx + Lx, d[i]) - Hx;
    l[i] = std::lower_bound(Hy, Hy + Ly, l[i]) - Hy;
    r[i] = std::lower_bound(Hy, Hy + Ly, r[i]) - Hy;
    for (int j = u[i] + 1; j <= d[i]; j++)
      G.add(j, Lx + Ly - 1 + i, 1000000000);
    for (int j = l[i] + 1; j <= r[i]; j++)
      G.add(Lx + Ly - 1 + i, Lx - 1 + j, 1000000000);
  }
  printf("%d\n", G());
  return 0;
}