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;
struct Edge {
  int t, f, next;
  Edge() {}
  Edge(int a, int b, int c) : t(a), f(b), next(c) {}
};
Edge e[1000000];
int head[305], vs, vt, tot = -1;
void addEdge(int x, int y, int z) {
  e[++tot] = Edge(y, z, head[x]);
  head[x] = tot;
  e[++tot] = Edge(x, 0, head[y]);
  head[y] = tot;
}
namespace Flow {
queue<int> q;
int dis[305], cur[305];
bool bfs() {
  memset(dis, 255, sizeof(dis));
  while (!q.empty()) q.pop();
  dis[vs] = 0;
  cur[vs] = head[vs];
  q.push(vs);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i != -1; i = e[i].next)
      if (e[i].f && dis[e[i].t] == -1) {
        int u = e[i].t;
        dis[u] = dis[x] + 1;
        cur[u] = head[u];
        if (u == vt) return 1;
        q.push(u);
      }
  }
  return 0;
}
int dfs(int x, int a) {
  if (x == vt || !a) return a;
  int ans = 0;
  for (int i = head[x]; i != -1; i = e[i].next)
    if (e[i].f && dis[e[i].t] == dis[x] + 1) {
      int u = e[i].t;
      int f = dfs(u, min(a, e[i].f));
      if (f) {
        e[i].f -= f;
        e[i ^ 1].f += f;
        ans += f;
        a -= f;
        if (!a) break;
      }
    }
  return ans;
}
int maxflow() {
  int ans = 0;
  while (bfs()) ans += dfs(vs, 0x3f3f3f3f);
  return ans;
}
}  // namespace Flow
struct Rec {
  int x1, x2, yy, y2;
  Rec() {}
  Rec(int a, int b, int c, int d) : x1(a), x2(b), yy(c), y2(d) {}
};
Rec a[55];
int val1[105], val2[105];
bool col[105][105];
int main() {
  memset(head, 255, sizeof(head));
  int n, m;
  scanf("%d%d", &n, &m);
  int cnt1 = 0, cnt2 = 0;
  val1[++cnt1] = 0;
  val1[++cnt1] = n;
  val2[++cnt2] = 0;
  val2[++cnt2] = n;
  for (int i = 1; i <= m; i++) {
    int x1, yy, x2, y2;
    scanf("%d%d%d%d", &x1, &yy, &x2, &y2);
    val1[++cnt1] = x1 - 1;
    val1[++cnt1] = x2;
    val2[++cnt2] = yy - 1;
    val2[++cnt2] = y2;
    a[i] = Rec(x1, x2, yy, y2);
  }
  sort(val1 + 1, val1 + cnt1 + 1);
  sort(val2 + 1, val2 + cnt2 + 1);
  cnt1 = unique(val1 + 1, val1 + cnt1 + 1) - val1 - 1;
  cnt2 = unique(val2 + 1, val2 + cnt2 + 1) - val2 - 1;
  for (int i = 1; i <= m; i++) {
    a[i].x1 = lower_bound(val1 + 1, val1 + cnt1 + 1, a[i].x1 - 1) - val1 + 1;
    a[i].x2 = lower_bound(val1 + 1, val1 + cnt1 + 1, a[i].x2) - val1;
    a[i].yy = lower_bound(val2 + 1, val2 + cnt2 + 1, a[i].yy - 1) - val2 + 1;
    a[i].y2 = lower_bound(val2 + 1, val2 + cnt2 + 1, a[i].y2) - val2;
    for (int j = a[i].x1; j <= a[i].x2; j++)
      for (int k = a[i].yy; k <= a[i].y2; k++) col[j][k] = 1;
  }
  vs = 0;
  vt = cnt1 + cnt2 + 1;
  for (int i = 1; i <= cnt1; i++) addEdge(vs, i, val1[i] - val1[i - 1]);
  for (int i = 1; i <= cnt2; i++) addEdge(cnt1 + i, vt, val2[i] - val2[i - 1]);
  for (int i = 1; i <= cnt1; i++)
    for (int j = 1; j <= cnt2; j++)
      if (col[i][j]) addEdge(i, cnt1 + j, 0x3f3f3f3f);
  printf("%d\n", Flow::maxflow());
  return 0;
}