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;
int n, m;
int a[53], b[53], c[53], d[53];
int mpx[103], cntx, mpy[103], cnty;
int g[102][102], w[102][102];
void init(void) {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d %d", a + i, b + i, c + i, d + i);
    mpx[i] = a[i], mpx[i + m] = ++c[i];
    mpy[i] = b[i], mpy[i + m] = ++d[i];
  }
  sort(mpx + 1, mpx + 1 + 2 * m);
  sort(mpy + 1, mpy + 1 + 2 * m);
  cntx = unique(mpx + 1, mpx + 1 + 2 * m) - mpx - 1;
  cnty = unique(mpy + 1, mpy + 1 + 2 * m) - mpy - 1;
  for (int i = 1; i <= m; i++) {
    a[i] = lower_bound(mpx + 1, mpx + 1 + cntx, a[i]) - mpx;
    b[i] = lower_bound(mpy + 1, mpy + 1 + cnty, b[i]) - mpy;
    c[i] = lower_bound(mpx + 1, mpx + 1 + cntx, c[i]) - mpx;
    d[i] = lower_bound(mpy + 1, mpy + 1 + cnty, d[i]) - mpy;
    g[a[i]][b[i]]++, g[c[i]][d[i]]++;
    g[a[i]][d[i]]--, g[c[i]][b[i]]--;
  }
  for (int i = 1; i <= cntx; i++)
    for (int j = 1; j <= cnty; j++)
      g[i][j] += g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1];
}
int head[205], to[20410], nxt[20410], flow[20410], cnt = 1;
void add(int u, int v, int f) {
  to[++cnt] = v, nxt[cnt] = head[u], flow[cnt] = f;
  head[u] = cnt;
}
void addedge(int u, int v, int f) { add(u, v, f), add(v, u, 0); }
int S, T;
void make_graph(void) {
  S = cntx + cnty + 1, T = cntx + cnty + 2;
  for (int i = 1; i < cntx; i++) addedge(S, i, mpx[i + 1] - mpx[i]);
  for (int i = 1; i < cnty; i++) addedge(i + cntx, T, mpy[i + 1] - mpy[i]);
  for (int i = 1; i < cntx; i++)
    for (int j = 1; j < cnty; j++)
      if (g[i][j]) addedge(i, j + cntx, 2147483647);
}
int deep[205];
queue<int> q;
bool bfs() {
  memset(deep + 1, 0, T * sizeof(int));
  q.push(S);
  deep[S] = 1;
  do {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i; i = nxt[i]) {
      int &y = to[i];
      if (!deep[y] && flow[i]) {
        deep[y] = deep[x] + 1;
        q.push(y);
      }
    }
  } while (!q.empty());
  return deep[T] != 0;
}
int dfs(int x, int f) {
  if (x == T) return f;
  int ans = 0;
  for (int i = head[x]; i; i = nxt[i]) {
    int &y = to[i];
    if (flow[i] && deep[y] == deep[x] + 1) {
      int more = dfs(y, min(flow[i], f));
      if (!more) {
        deep[y] = -1;
        continue;
      }
      flow[i] -= more, flow[i ^ 1] += more;
      ans += more, f -= more;
      if (!f) break;
    }
  }
  return ans;
}
int dinic() {
  int ans = 0;
  while (bfs()) ans += dfs(S, 2147483647);
  return ans;
}
int main() {
  init();
  make_graph();
  cout << dinic() << endl;
}