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 long long M = 550, INF = 0x7fffffff;
struct noder {
  long long x, y;
};
struct edger {
  long long to, nxt, w;
} edge[M * M];
long long n, m, rangex, rangey, cntx, cnty, tmpx[M], tmpy[M];
long long s, t, cntedge = 1, head[M], tmphead[M];
pair<noder, noder> sqr[M];
void add(long long u, long long v, long long w) {
  edge[++cntedge].to = v;
  edge[cntedge].nxt = head[u];
  edge[cntedge].w = w;
  head[u] = cntedge;
}
void discreate() {
  for (long long i = 1; i <= m; i++) {
    tmpx[++cntx] = sqr[i].first.x, tmpy[++cnty] = sqr[i].first.y;
    tmpx[++cntx] = sqr[i].second.x, tmpy[++cnty] = sqr[i].second.y;
  }
  sort(tmpx + 1, tmpx + 1 + cntx);
  sort(tmpy + 1, tmpy + 1 + cnty);
  rangex = unique(tmpx + 1, tmpx + 1 + cntx) - tmpx - 1;
  rangey = unique(tmpy + 1, tmpy + 1 + cnty) - tmpy - 1;
  for (long long i = 1; i <= m; i++) {
    sqr[i].first.x =
        lower_bound(tmpx + 1, tmpx + 1 + rangex, sqr[i].first.x) - tmpx;
    sqr[i].first.y =
        lower_bound(tmpy + 1, tmpy + 1 + rangey, sqr[i].first.y) - tmpy;
    sqr[i].second.x =
        lower_bound(tmpx + 1, tmpx + 1 + rangex, sqr[i].second.x) - tmpx;
    sqr[i].second.y =
        lower_bound(tmpy + 1, tmpy + 1 + rangey, sqr[i].second.y) - tmpy;
  }
}
void build() {
  s = 0, t = rangex + rangey + 1;
  for (long long i = 1; i < rangex; i++)
    add(s, i, tmpx[i + 1] - tmpx[i]), add(i, s, 0);
  for (long long i = 1; i < rangey; i++)
    add(i + rangex, t, tmpy[i + 1] - tmpy[i]), add(t, i + rangex, 0);
  for (long long i = 1; i <= m; i++)
    for (long long x = sqr[i].first.x; x < sqr[i].second.x; x++)
      for (long long y = sqr[i].first.y; y < sqr[i].second.y; y++)
        add(x, y + rangex, INF), add(y + rangex, x, 0);
}
namespace dinic {
long long depth[M];
bool bfs() {
  memset(depth, 0, sizeof(depth));
  queue<long long> q;
  q.push(s);
  depth[s] = 1;
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    for (long long i = head[u]; i; i = edge[i].nxt) {
      long long v = edge[i].to, w = edge[i].w;
      if (w && !depth[v]) depth[v] = depth[u] + 1, q.push(v);
    }
  }
  return depth[t];
}
long long dfs(long long u, long long flow) {
  if (u == t || !flow) return flow;
  long long res = 0;
  for (long long &i = tmphead[u]; i; i = edge[i].nxt) {
    long long v = edge[i].to, &w = edge[i].w, &fw = edge[i ^ 1].w;
    if (!w || depth[v] != depth[u] + 1) continue;
    long long inc = dfs(v, min(w, flow));
    w -= inc, fw += inc;
    res += inc, flow -= inc;
    if (!flow) break;
  }
  if (!res) depth[u] = -1;
  return res;
}
void solve() {
  long long ans = 0, inc = 0;
  while (bfs()) {
    memcpy(tmphead, head, sizeof(head));
    while (inc = dfs(s, INF)) ans += inc;
  }
  printf("%lld\n", ans);
}
}  // namespace dinic
signed main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= m; i++) {
    scanf("%lld%lld", &sqr[i].first.x, &sqr[i].first.y);
    scanf("%lld%lld", &sqr[i].second.x, &sqr[i].second.y);
    sqr[i].second.x++, sqr[i].second.y++;
  }
  discreate();
  build();
  dinic::solve();
  return 0;
}