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 = 1e5 + 10;
const int INF = 2e9;
struct edge {
  int to, w, nxt;
} e[N << 1];
int n, tot, totx, toty, S, T;
int head[N], dep[N], xl[N], xr[N], yl[N], yr[N], tmpx[N], tmpy[N];
template <typename T>
inline void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= f;
}
inline void addedge(int u, int v, int w) {
  ++tot;
  e[tot] = (edge){v, w, head[u]};
  head[u] = tot;
  ++tot;
  e[tot] = (edge){u, 0, head[v]};
  head[v] = tot;
}
inline bool BFS() {
  queue<int> Q;
  while (!Q.empty()) Q.pop();
  for (int i = 1; i <= T; ++i) dep[i] = -1;
  dep[S] = 0;
  Q.push(S);
  while (!Q.empty()) {
    int cur = Q.front();
    Q.pop();
    for (int i = head[cur]; i; i = e[i].nxt) {
      int v = e[i].to, w = e[i].w;
      if (w > 0 && dep[v] == -1) {
        dep[v] = dep[cur] + 1;
        Q.push(v);
        if (v == T) return true;
      }
    }
  }
  return false;
}
inline int dinic(int u, int flow) {
  int rest = flow, k;
  if (u == T) return flow;
  for (int i = head[u]; i && rest; i = e[i].nxt) {
    int v = e[i].to, w = e[i].w;
    if (w > 0 && dep[v] == dep[u] + 1) {
      k = dinic(v, min(rest, w));
      e[i].w -= k;
      e[i ^ 1].w += k;
      rest -= k;
      if (!k) dep[v] = -1;
    }
  }
  return flow - rest;
}
int main() {
  read(n);
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(xl[i]);
    read(yl[i]);
    read(xr[i]);
    read(yr[i]);
    tmpx[++totx] = xl[i];
    tmpx[++totx] = xr[i] + 1;
    tmpy[++toty] = yl[i];
    tmpy[++toty] = yr[i] + 1;
  }
  sort(tmpx + 1, tmpx + totx + 1);
  sort(tmpy + 1, tmpy + toty + 1);
  totx = unique(tmpx + 1, tmpx + totx + 1) - tmpx - 1;
  toty = unique(tmpy + 1, tmpy + toty + 1) - tmpy - 1;
  for (int i = 1; i <= n; ++i) {
    xl[i] = lower_bound(tmpx + 1, tmpx + totx + 1, xl[i]) - tmpx;
    xr[i] = lower_bound(tmpx + 1, tmpx + totx + 1, xr[i] + 1) - tmpx - 1;
    yl[i] = lower_bound(tmpy + 1, tmpy + toty + 1, yl[i]) - tmpy;
    yr[i] = lower_bound(tmpy + 1, tmpy + toty + 1, yr[i] + 1) - tmpy - 1;
  }
  --totx;
  --toty;
  S = 1, T = totx + toty + 2;
  tot = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = xl[i]; j <= xr[i]; ++j)
      for (int k = yl[i]; k <= yr[i]; ++k) addedge(1 + j, 1 + totx + k, INF);
  for (int i = 1; i <= totx; ++i) addedge(S, 1 + i, tmpx[i + 1] - tmpx[i]);
  for (int i = 1; i <= toty; ++i)
    addedge(1 + totx + i, T, tmpy[i + 1] - tmpy[i]);
  int ans = 0;
  while (BFS()) {
    while (int flw = dinic(S, INF)) ans += flw;
  }
  printf("%d\n", ans);
  return 0;
}