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 = 1e4, M = 55, E = 1e6, INF = 1e9;
int n, m;
int xl[M], yl[M], xr[M], yr[M];
int bx[M << 1], by[M << 1], tx, ty;
int h[N], to[E], nxt[E], flow[E], ecnt = 1, hh[N];
inline void adde(int u, int v, int w) {
  nxt[++ecnt] = h[u];
  h[u] = ecnt;
  to[ecnt] = v;
  flow[ecnt] = w;
}
inline void add(int u, int v, int w) {
  adde(u, v, w);
  adde(v, u, 0);
}
int vis[N], dep[N], S, T, gap[N];
inline void bfs() {
  static queue<int> q;
  q.push(T);
  dep[T] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = h[u], v; i; i = nxt[i])
      if (!dep[v = to[i]]) gap[dep[v] = dep[u] + 1]++, q.push(v);
  }
}
inline int dfs(int u = S, int lim = INF) {
  if (u == T) return lim;
  int ret = 0;
  for (int &i = hh[u], v; i; i = nxt[i])
    if (flow[i] && dep[v = to[i]] == dep[u] - 1) {
      int del = dfs(v, min(lim - ret, flow[i]));
      if (del) {
        flow[i] -= del;
        flow[i ^ 1] += del;
        ret += del;
        if (ret == del) return ret;
      }
    }
  if (!--gap[dep[u]]) dep[S] = T + 6;
  gap[++dep[u]]++;
  return ret;
}
inline int mf() {
  bfs();
  int ret = 0;
  while (dep[S] <= T + 5) memcpy(hh, h, sizeof h), ret += dfs();
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++)
    scanf("%d%d%d%d", &xl[i], &yl[i], &xr[i], &yr[i]),
        bx[++tx] = xl[i] - 1, bx[++tx] = xr[i], by[++ty] = yl[i] - 1,
        by[++ty] = yr[i];
  bx[++tx] = 0;
  bx[++tx] = n;
  by[++ty] = 0;
  by[++ty] = n;
  sort(bx + 1, bx + tx + 1);
  tx = unique(bx + 1, bx + tx + 1) - bx - 1;
  sort(by + 1, by + ty + 1);
  ty = unique(by + 1, by + ty + 1) - by - 1;
  T = tx + ty + 1;
  for (int i = 1; i <= m; i++) {
    xl[i] = lower_bound(bx + 1, bx + tx + 1, xl[i] - 1) - bx;
    xr[i] = lower_bound(bx + 1, bx + tx + 1, xr[i]) - bx;
    yl[i] = lower_bound(by + 1, by + ty + 1, yl[i] - 1) - by;
    yr[i] = lower_bound(by + 1, by + ty + 1, yr[i]) - by;
    for (int j = xl[i]; j < xr[i]; j++)
      for (int k = yl[i]; k < yr[i]; k++) add(j, k + tx, INF);
  }
  for (int i = 1; i < tx; i++) add(S, i, bx[i + 1] - bx[i]);
  for (int i = 1; i < ty; i++) add(i + tx, T, by[i + 1] - by[i]);
  printf("%d\n", mf());
  return 0;
}