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 = 2e9;
const int MAXN = 900;
const int MAXM = 1900000;
int N, edges;
int last[MAXN], preve[MAXM], head[MAXM];
int Cap[MAXM], Flow[MAXM];
int dist[MAXN];
int nextEdge[MAXN];
queue<int> Q;
void init(int N) {
  edges = 0;
  memset(last, -1, sizeof last);
}
set<int> namex, namey;
vector<int> xx, yy;
void handlex(int f) {
  if (namex.find(f) != namex.end()) return;
  namex.insert(f);
  xx.push_back(f);
}
void handley(int f) {
  if (namey.find(f) != namey.end()) return;
  yy.push_back(f);
  namey.insert(f);
}
inline void add_edge(int u, int v, int cap, int flow = 0) {
  head[edges] = v;
  preve[edges] = last[u];
  Cap[edges] = cap;
  Flow[edges] = flow;
  last[u] = edges++;
  head[edges] = u;
  preve[edges] = last[v];
  Cap[edges] = 0;
  Flow[edges] = 0;
  last[v] = edges++;
}
inline bool dinicBfs(int S, int E, int N) {
  int from = S, to, cap, flow;
  memset(dist, 0, sizeof(int) * N);
  dist[from] = 1;
  while (!Q.empty()) Q.pop();
  Q.push(from);
  while (!Q.empty()) {
    from = Q.front();
    Q.pop();
    for (int e = last[from]; e >= 0; e = preve[e]) {
      to = head[e];
      cap = Cap[e];
      flow = Flow[e];
      if (!dist[to] && cap > flow) {
        dist[to] = dist[from] + 1;
        Q.push(to);
        if (to == E) return true;
      }
    }
  }
  return (dist[E] != 0);
}
inline int dfs(int from, int minEdge, int E) {
  if (!minEdge) return 0;
  if (from == E) return minEdge;
  int to, e, cap, flow, ret;
  for (; nextEdge[from] >= 0; nextEdge[from] = preve[e]) {
    e = nextEdge[from];
    to = head[e];
    cap = Cap[e];
    flow = Flow[e];
    if (dist[to] != dist[from] + 1) continue;
    ret = dfs(to, min(minEdge, cap - flow), E);
    if (ret) {
      Flow[e] += ret;
      Flow[e ^ 1] -= ret;
      return ret;
    }
  }
  return 0;
}
int dinicUpdate(int S, int E) {
  int flow = 0;
  while (int minEdge = dfs(S, INF, E)) {
    if (minEdge == 0) break;
    flow += minEdge;
  }
  return flow;
}
int maxFlow(int S, int E, int N) {
  int totFlow = 0;
  while (dinicBfs(S, E, N)) {
    for (int i = 0; i <= N; i++) nextEdge[i] = last[i];
    totFlow += dinicUpdate(S, E);
  }
  return totFlow;
}
int x1[60], y11[60], x2[60], y2[60];
int main() {
  int i, j, k, l, m, n;
  init(32);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &x1[i], &y11[i], &x2[i], &y2[i]);
    x2[i]++;
    y2[i]++;
    handlex(x1[i]);
    handlex(x2[i]);
    handley(y11[i]);
    handley(y2[i]);
  }
  sort(xx.begin(), xx.end());
  sort(yy.begin(), yy.end());
  int so = xx.size() + yy.size() + 1;
  int sink = so + 1;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j < xx.size(); j++) {
      if (xx[j] <= x1[i]) continue;
      if (xx[j] > x2[i]) break;
      for (int k = 1; k < yy.size(); k++) {
        if (yy[k] <= y11[i]) continue;
        if (yy[k] > y2[i]) break;
        int g = xx.size() + k;
        add_edge(j, g, INF);
      }
    }
  }
  for (int i = 1; i < xx.size(); i++) {
    add_edge(so, i, xx[i] - xx[i - 1]);
  }
  for (int i = 1; i < yy.size(); i++) {
    int g = xx.size() + i;
    add_edge(g, sink, yy[i] - yy[i - 1]);
  }
  int ans = maxFlow(so, sink, sink + 2);
  cout << ans << endl;
}