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 = 500500;
const int inf = 1e9;
struct edge {
  int obj, pre, c;
} e[maxn * 2];
int n, m, cntx, cnty, tot, s, t;
int head[maxn], cur[maxn], uu[maxn], cx[maxn], cy[maxn];
struct node {
  int a, b, c, d;
  node() {}
  void read() { scanf("%d%d%d%d", &a, &b, &c, &d); }
} a[maxn];
void insert(int x, int y, int c) {
  e[++tot].obj = y;
  e[tot].pre = head[x];
  head[x] = tot;
  e[tot].c = c;
  e[++tot].obj = x;
  e[tot].pre = head[y];
  head[y] = tot;
  e[tot].c = 0;
}
bool bfs() {
  for (int i = 0; i <= t; i++) uu[i] = -1;
  queue<int> q;
  q.push(0);
  uu[0] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int j = head[u]; j; j = e[j].pre) {
      int v = e[j].obj;
      if (uu[v] == -1 && e[j].c) uu[v] = uu[u] + 1, q.push(v);
    }
  }
  if (uu[t] == -1)
    return 0;
  else
    return 1;
}
int dfs(int x, int mx) {
  if (x == t) return mx;
  int used = 0;
  for (int j = cur[x]; j; j = e[j].pre) {
    int v = e[j].obj;
    if (uu[v] == uu[x] + 1 && e[j].c) {
      int w = dfs(v, min(e[j].c, mx - used));
      e[j].c -= w;
      e[j ^ 1].c += w;
      used += w;
      if (e[j].c) cur[x] = j;
      if (used == mx) return mx;
    }
  }
  if (!used) uu[x] = -1;
  return used;
}
int dinic() {
  int ans = 0;
  while (bfs()) {
    for (int i = 0; i <= t; i++) cur[i] = head[i];
    ans += dfs(0, inf);
  }
  return ans;
}
bool jud(int a, int b, int c, int d) {
  for (int i = 1; i <= m; i++) {
    node &p = ::a[i];
    if (p.a <= a && p.b <= b && c <= p.c && d <= p.d) {
      return 1;
    }
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    a[i].read();
    cx[++cntx] = a[i].a;
    cx[++cntx] = a[i].c + 1;
    cy[++cnty] = a[i].b;
    cy[++cnty] = a[i].d + 1;
  }
  sort(cx + 1, cx + 1 + cntx);
  cntx = unique(cx + 1, cx + 1 + cntx) - cx - 1;
  sort(cy + 1, cy + 1 + cnty);
  cnty = unique(cy + 1, cy + 1 + cnty) - cy - 1;
  s = 0;
  t = cntx + cnty + 1;
  tot = 1;
  for (int i = 1; i <= cntx - 1; i++) {
    insert(s, i, cx[i + 1] - cx[i]);
  }
  for (int i = 1; i <= cnty - 1; i++) {
    insert(cntx + i, t, cy[i + 1] - cy[i]);
  }
  for (int i = 1; i <= cntx - 1; i++) {
    int a = cx[i], c = cx[i + 1];
    for (int j = 1; j <= cnty - 1; j++) {
      int b = cy[j], d = cy[j + 1];
      if (jud(a, b, c - 1, d - 1)) insert(i, cntx + j, inf);
    }
  }
  printf("%d\n", dinic());
  return 0;
}