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 = (int)2e5 + 100;
const int mod = (int)1e9 + 7;
const int inf = (int)1e9;
int n, m, S, T, vis[110][110], lx[110], ly[110], px, py;
struct que {
  int x1, x2, y1, y2;
} a[110];
int tot = 1, head[maxn << 1], dep[maxn], iter[maxn], Q[maxn];
struct node {
  int u, v, nxt, w;
} g[maxn << 1];
void add(int u, int v, int w) {
  g[++tot] = {u, v, head[u], w};
  head[u] = tot;
  g[++tot] = {v, u, head[v], 0};
  head[v] = tot;
}
int bfs() {
  for (auto i = (1); i <= (T); ++i) dep[i] = 0, iter[i] = head[i];
  int ql = 0, qr = 0;
  Q[++qr] = S;
  dep[S] = 1;
  while (ql < qr) {
    int x = Q[++ql];
    for (int i = head[x]; i; i = g[i].nxt)
      if (!dep[g[i].v] && g[i].w) dep[g[i].v] = dep[x] + 1, Q[++qr] = g[i].v;
  }
  return dep[T];
}
int dfs(int x, int f) {
  if (x == T || !f) return f;
  int sf = 0;
  for (int i = iter[x]; i; i = g[i].nxt)
    if (dep[g[i].v] == dep[x] + 1 && g[i].w) {
      int w = dfs(g[i].v, min(g[i].w, f));
      if (f) {
        g[i].w -= w;
        g[i ^ 1].w += w;
        f -= w;
        sf += w;
      }
    }
  return sf;
}
int dinic() {
  int ans = 0;
  while (bfs()) ans += dfs(S, inf);
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (auto i = (1); i <= (m); ++i) {
    scanf("%d%d%d%d", &a[i].x1, &a[i].y1, &a[i].x2, &a[i].y2);
    a[i].x2++;
    a[i].y2++;
    lx[++px] = a[i].x1;
    lx[++px] = a[i].x2;
    ly[++py] = a[i].y1;
    ly[++py] = a[i].y2;
  }
  sort(lx + 1, lx + 1 + px);
  sort(ly + 1, ly + 1 + py);
  px = unique(lx + 1, lx + 1 + px) - lx - 1;
  py = unique(ly + 1, ly + 1 + py) - ly - 1;
  S = px + py + 1;
  T = S + 1;
  for (auto i = (1); i <= (px - 1); ++i) add(S, i, lx[i + 1] - lx[i]);
  for (auto i = (1); i <= (py - 1); ++i) add(px + i, T, ly[i + 1] - ly[i]);
  for (auto i = (1); i <= (m); ++i) {
    int x1 = lower_bound(lx + 1, lx + 1 + px, a[i].x1) - lx,
        x2 = lower_bound(lx + 1, lx + 1 + px, a[i].x2) - lx;
    int y1 = lower_bound(ly + 1, ly + 1 + py, a[i].y1) - ly,
        y2 = lower_bound(ly + 1, ly + 1 + py, a[i].y2) - ly;
    for (auto x = (x1); x <= (x2 - 1); ++x)
      for (auto y = (y1); y <= (y2 - 1); ++y)
        if (!vis[x][y]) vis[x][y] = 1, add(x, px + y, inf);
  }
  printf("%d\n", dinic());
}