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 inf = 1e9;
int n, m, s, t, h[405], tt = 1;
struct node {
  int x1, y1, x2, y2;
} A[405];
bool eg[405][405];
int B1[405 * 405], b1, B2[405 * 405], b2;
struct edge {
  int nxt, to, co;
} G[405 * 405];
void Add(int a, int b, int c) {
  if (eg[a][b]) return;
  G[++tt] = (edge){h[a], b, c};
  h[a] = tt;
  eg[a][b] = 1;
}
int dep[405], cur[405];
queue<int> Q;
bool bfs() {
  memset(dep, -1, sizeof(dep));
  for (int i = s; i <= t; i++) cur[i] = h[i];
  while (!Q.empty()) Q.pop();
  Q.push(s);
  dep[s] = 0;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = h[x]; i; i = G[i].nxt) {
      int u = G[i].to, c = G[i].co;
      if (dep[u] != -1 || !c) continue;
      dep[u] = dep[x] + 1;
      if (u == t) return 1;
      Q.push(u);
    }
  }
  return 0;
}
int dfs(int x, int mi) {
  if (x == t || !mi) return mi;
  int rlow = 0, used = 0;
  for (int& i = cur[x]; i; i = G[i].nxt) {
    int u = G[i].to, c = G[i].co;
    if (dep[u] != dep[x] + 1 || !c) continue;
    if (rlow = dfs(u, min(c, mi - used))) {
      used += rlow;
      G[i].co -= rlow;
      G[i ^ 1].co += rlow;
      if (used == mi) break;
    }
  }
  return used;
}
int ans = 0;
void Dinic() {
  while (bfs()) ans += dfs(s, inf);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &A[i].x1, &A[i].y1, &A[i].x2, &A[i].y2);
    B1[++b1] = A[i].x1;
    B1[++b1] = ++A[i].x2;
    B2[++b2] = A[i].y1;
    B2[++b2] = ++A[i].y2;
  }
  B1[++b1] = B2[++b2] = n + 1;
  sort(B1 + 1, B1 + b1 + 1);
  sort(B2 + 1, B2 + b2 + 1);
  b1 = unique(B1 + 1, B1 + b1 + 1) - B1 - 1;
  b2 = unique(B2 + 1, B2 + b2 + 1) - B2 - 1;
  s = 0, t = b1 + b2 + 1;
  for (int i = 1; i <= m; i++) {
    A[i].x1 = lower_bound(B1 + 1, B1 + b1 + 1, A[i].x1) - B1;
    A[i].x2 = lower_bound(B1 + 1, B1 + b1 + 1, A[i].x2) - B1;
    A[i].y1 = lower_bound(B2 + 1, B2 + b2 + 1, A[i].y1) - B2;
    A[i].y2 = lower_bound(B2 + 1, B2 + b2 + 1, A[i].y2) - B2;
    for (int x = A[i].x1; x < A[i].x2; x++)
      for (int y = A[i].y1; y < A[i].y2; y++)
        Add(x, y + b1, inf), Add(y + b1, x, 0);
  }
  for (int i = 1; i < b1; i++) {
    Add(s, i, B1[i + 1] - B1[i]);
    Add(i, s, 0);
  }
  for (int i = 1; i < b2; i++) {
    Add(i + b1, t, B2[i + 1] - B2[i]);
    Add(t, i + b1, 0);
  }
  Dinic();
  printf("%d\n", ans);
  return 0;
}