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 M = 105;
const int Inf = 2e9;
int n;
int L[M], R[M], U[M], D[M];
struct sdnode {
  int id, v, ty;
  bool operator<(const sdnode &b) const { return v < b.v; }
} B[M];
int btot, ctot, rtot;
int Shadc[M], Shadr[M];
void Shadmay() {
  for (int i = 1; i <= n; i++) B[++btot] = (sdnode){i, L[i], 0};
  for (int i = 1; i <= n; i++) B[++btot] = (sdnode){i, R[i] + 1, 1};
  sort(B + 1, B + btot + 1);
  for (int i = 1; i <= btot; i++) {
    if (i == 1 or B[i].v != B[i - 1].v) Shadc[++ctot] = B[i].v;
    if (B[i].ty == 0) L[B[i].id] = ctot;
    if (B[i].ty == 1) R[B[i].id] = ctot;
  }
  btot = 0;
  for (int i = 1; i <= n; i++) B[++btot] = (sdnode){i, U[i], 0};
  for (int i = 1; i <= n; i++) B[++btot] = (sdnode){i, D[i] + 1, 1};
  sort(B + 1, B + btot + 1);
  for (int i = 1; i <= btot; i++) {
    if (i == 1 or B[i].v != B[i - 1].v) Shadr[++rtot] = B[i].v;
    if (B[i].ty == 0) U[B[i].id] = rtot;
    if (B[i].ty == 1) D[B[i].id] = rtot;
  }
  ctot--;
  rtot--;
}
namespace NetworkFlow {
const int MM = 505;
struct Edge {
  int v, to, flow;
} E[50005];
int Head[MM], e_tot = 1;
void Link(int u, int v, int flow) {
  E[++e_tot] = (Edge){v, Head[u], flow}, Head[u] = e_tot;
}
void Linke(int u, int v, int flow) {
  Link(v, u, 0);
  Link(u, v, flow);
}
int tot, s, t;
int dep[MM], cur[MM];
bool vis[MM];
int Q[MM], l, r;
bool bfs() {
  for (int i = 1; i <= tot; i++) vis[i] = false, cur[i] = Head[i];
  l = r = 0;
  Q[r++] = s;
  vis[s] = true;
  while (l < r) {
    int u = Q[l++];
    for (int i = Head[u]; i; i = E[i].to) {
      int v = E[i].v;
      if (vis[v] or !E[i].flow) continue;
      vis[v] = true;
      dep[v] = dep[u] + 1;
      Q[r++] = v;
      if (v == t) return true;
    }
  }
  return false;
}
int dfs(int u, int rest) {
  if (u == t or !rest) return rest;
  int don, sm = 0;
  for (int &i = cur[u]; i; i = E[i].to) {
    int v = E[i].v;
    if (dep[v] != dep[u] + 1 or !E[i].flow) continue;
    sm += (don = dfs(v, min(rest, E[i].flow)));
    E[i].flow -= don;
    E[i ^ 1].flow += don;
    if (!(rest -= don)) break;
  }
  return sm;
}
int Dinic() {
  int Maxflow = 0;
  while (bfs()) Maxflow += dfs(s, Inf);
  return Maxflow;
}
};  // namespace NetworkFlow
using namespace NetworkFlow;
bool Mk[M][M];
int Er[M], Ec[M];
void Solve() {
  Shadmay();
  for (int i = 1; i <= n; i++)
    for (int j = U[i]; j < D[i]; j++)
      for (int q = L[i]; q < R[i]; q++) Mk[j][q] = true;
  tot = rtot + ctot + 2;
  s = tot - 1;
  t = tot;
  for (int i = 1; i <= rtot; i++)
    Linke(s, i, Shadr[i + 1] - Shadr[i]), Er[i] = e_tot;
  for (int i = 1; i <= ctot; i++)
    Linke(i + rtot, t, Shadc[i + 1] - Shadc[i]), Ec[i] = e_tot;
  for (int i = 1; i <= rtot; i++)
    for (int j = 1; j <= ctot; j++)
      if (Mk[i][j]) Linke(i, j + rtot, Inf);
  int dinic = Dinic();
  printf("%d\n", dinic);
}
int main() {
  scanf("%*d%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d%d%d", &U[i], &L[i], &D[i], &R[i]);
  Solve();
  return 0;
}