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 INF = 0x7f7f7f7f;
int n, m, s, t;
int cntx, ux[1005], cnty, uy[1005];
pair<pair<int, int>, pair<int, int> > a[1005];
int mxf;
int ee = 1, h[500005], nex[500005 << 1], to[500005 << 1], val[500005 << 1];
int dep[500005];
void addedge(int first, int second, int z) {
  nex[++ee] = h[first];
  to[ee] = second;
  val[ee] = z;
  h[first] = ee;
}
bool bfs() {
  memset(dep, 0, sizeof(dep));
  queue<int> q;
  dep[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int first = q.front();
    q.pop();
    for (int i = h[first]; i; i = nex[i])
      if (val[i] && dep[to[i]] == 0) {
        dep[to[i]] = dep[first] + 1;
        q.push(to[i]);
      }
  }
  return dep[t] != 0;
}
int dfs(int first, int flow) {
  if (first == t) return flow;
  for (int i = h[first]; i; i = nex[i])
    if (val[i] && dep[to[i]] == dep[first] + 1) {
      int d = dfs(to[i], min(flow, val[i]));
      if (d > 0) {
        val[i] -= d;
        val[i ^ 1] += d;
        return d;
      }
    }
  return 0;
}
void dinic() {
  mxf = 0;
  while (bfs()) {
    int first = 1;
    while (first != 0) {
      first = dfs(s, INF);
      mxf += first;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m && cin >> a[i].first.first >> a[i].first.second >>
                                a[i].second.first >> a[i].second.second;
       i++) {
    a[i].second.first++, a[i].second.second++;
    ux[++cntx] = a[i].first.first, ux[++cntx] = a[i].second.first;
    uy[++cnty] = a[i].first.second, uy[++cnty] = a[i].second.second;
  }
  ux[++cntx] = uy[++cnty] = n + 1;
  sort(ux + 1, ux + 1 + cntx), sort(uy + 1, uy + 1 + cnty);
  cntx = unique(ux + 1, ux + 1 + cntx) - ux - 1,
  cnty = unique(uy + 1, uy + 1 + cnty) - uy - 1;
  s = 0, t = cntx + cnty + 1;
  for (int i = 1; i < cntx; i++)
    addedge(s, i, ux[i + 1] - ux[i]), addedge(i, s, 0);
  for (int i = 1; i < cnty; i++)
    addedge(i + cntx, t, uy[i + 1] - uy[i]), addedge(t, i + cntx, 0);
  for (int i = 1; i <= m; i++) {
    a[i].first.first =
        lower_bound(ux + 1, ux + 1 + cntx, a[i].first.first) - ux,
    a[i].second.first =
        lower_bound(ux + 1, ux + 1 + cntx, a[i].second.first) - ux;
    a[i].first.second =
        lower_bound(uy + 1, uy + 1 + cnty, a[i].first.second) - uy,
    a[i].second.second =
        lower_bound(uy + 1, uy + 1 + cnty, a[i].second.second) - uy;
    for (int k = a[i].first.first; k < a[i].second.first; k++)
      for (int j = a[i].first.second; j < a[i].second.second; j++)
        addedge(k, j + cntx, INF), addedge(j + cntx, k, 0);
  }
  dinic();
  cout << mxf << endl;
  return 0;
}