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 N = 10005, E = 200005;
int Head[N], Next[E], Adj[E], Flow[E], tot = 1;
inline void addedge(int u, int v, int w) {
  Next[++tot] = Head[u], Head[u] = tot, Adj[tot] = v, Flow[tot] = w;
  Next[++tot] = Head[v], Head[v] = tot, Adj[tot] = u, Flow[tot] = 0;
}
int S, T, level[N];
int Q[N];
inline bool bfs() {
  memset(level, -1, sizeof(level));
  int l = 1, r = 0;
  Q[++r] = S, level[S] = 0;
  while (l <= r) {
    int x = Q[l++];
    for (int e = Head[x]; e; e = Next[e])
      if (level[Adj[e]] == -1 && Flow[e])
        level[Adj[e]] = level[x] + 1, Q[++r] = Adj[e];
  }
  return level[T] != -1;
}
inline int dfs(int x, int flow) {
  if (x == T || !flow) return flow;
  int ret = 0, c;
  for (int e = Head[x]; e; e = Next[e])
    if (level[Adj[e]] == level[x] + 1 && Flow[e] &&
        (c = dfs(Adj[e], min(flow - ret, Flow[e])))) {
      ret += c;
      Flow[e] -= c, Flow[e ^ 1] += c;
      if (ret == flow) break;
    }
  if (!ret) level[x] = -1;
  return ret;
}
struct Node {
  int x1, y1, x2, y2;
} p[N];
int p1[N], p2[N];
int n, m, ans = 0;
inline bool judge(int a, int b, int c, int d) {
  for (int i = 1; i <= m; i++)
    if (p[i].x1 <= a && p[i].y1 <= b && c <= p[i].x2 && d <= p[i].y2)
      return true;
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &p[i].x1, &p[i].y1, &p[i].x2, &p[i].y2);
    p1[i * 2 - 1] = p[i].x1, p1[i * 2] = p[i].x2 + 1;
    p2[i * 2 - 1] = p[i].y1, p2[i * 2] = p[i].y2 + 1;
  }
  sort(p1 + 1, p1 + m * 2 + 1);
  sort(p2 + 1, p2 + m * 2 + 1);
  int v1 = unique(p1 + 1, p1 + m * 2 + 1) - p1 - 1;
  int v2 = unique(p2 + 1, p2 + m * 2 + 1) - p2 - 1;
  S = v1 + v2 + 1, T = S + 1;
  for (int i = 1; i < v1; i++) addedge(S, i, p1[i + 1] - p1[i]);
  for (int i = 1; i < v2; i++) addedge(i + v1, T, p2[i + 1] - p2[i]);
  for (int i = 1; i < v1; i++)
    for (int j = 1; j < v2; j++)
      if (judge(p1[i], p2[j], p1[i + 1] - 1, p2[j + 1] - 1))
        addedge(i, j + v1, 1 << 30);
  while (bfs()) ans += dfs(S, 1 << 30);
  printf("%d", ans);
  return 0;
}