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;
using LL = long long;
using PII = pair<int, int>;
template <typename T>
struct MaxFlow {
  struct Edge {
    int u, v;
    T c, f;
  };
  const T eps = (T)1e-9;
  vector<Edge> E;
  int n, src, sink;
  vector<vector<int>> G;
  vector<int> P, D;
  T flow = T();
  MaxFlow(int n, int src, int sink)
      : n(n), src(src), sink(sink), G(n), P(n), D(n) {}
  void clear_flow() {
    for (auto& e : E) e.f = T();
    flow = T();
  }
  void reduce() {
    for (auto& e : E) e.c -= e.f;
  }
  void add_edge(int u, int v, T cap) {
    assert(0 <= u && u < n && 0 <= v && v < n);
    G[u].push_back(E.size()), E.push_back({u, v, cap, T()});
    G[v].push_back(E.size()), E.push_back({v, u, T(), T()});
  }
  bool expath() {
    fill(D.begin(), D.end(), -1);
    queue<int> Q;
    Q.push(sink), D[sink] = 0;
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (int id : G[u]) {
        const Edge &e = E[id], &b = E[id ^ 1];
        if (b.c - b.f > eps && D[e.v] == -1) {
          D[e.v] = D[e.u] + 1, Q.push(e.v);
          if (e.v == src) return true;
        }
      }
    }
    return false;
  }
  T dfs(int u, T w) {
    if (u == sink) return w;
    for (int& i = P[u]; i < int(G[u].size()); i++) {
      int id = G[u][i];
      const Edge& e = E[id];
      if (e.c - e.f > eps && D[e.v] == D[e.u] - 1) {
        T t = dfs(e.v, min(e.c - e.f, w));
        if (t > eps) return E[id].f += t, E[id ^ 1].f -= t, t;
      }
    }
    return T();
  }
  const T max_flow() {
    while (expath()) {
      fill(P.begin(), P.end(), 0);
      T tot = T();
      for (;;) {
        T add = dfs(src, numeric_limits<T>::max());
        if (add <= eps) break;
        tot += add;
      }
      if (tot <= eps) break;
      flow += tot;
    }
    return flow;
  }
  vector<int> min_cut() {
    max_flow();
    vector<int> R(n);
    for (int i = 0; i < n; i++) R[i] = (D[i] != -1);
    return R;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) return puts("0"), 0;
  vector<int> xs, ys, x1(m), x2(m), y1(m), y2(m);
  for (int i = 0; i < m; i++) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    x2[i]++;
    y2[i]++;
    xs.push_back(x1[i]);
    xs.push_back(x2[i]);
    ys.push_back(y1[i]);
    ys.push_back(y2[i]);
  }
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
  ys.resize(unique(ys.begin(), ys.end()) - ys.begin());
  int nx = xs.size() - 1, ny = ys.size() - 1;
  int src = nx + ny, sink = nx + ny + 1;
  MaxFlow<LL> mf(sink + 1, src, sink);
  for (int i = 0; i < nx; i++) mf.add_edge(src, i, xs[i + 1] - xs[i]);
  for (int i = 0; i < ny; i++) mf.add_edge(i + nx, sink, ys[i + 1] - ys[i]);
  for (int i = 0; i < nx; i++) {
    for (int j = 0; j < ny; j++) {
      for (int k = 0; k < m; k++) {
        if (xs[i] >= x1[k] && xs[i + 1] <= x2[k] && ys[j] >= y1[k] &&
            ys[j + 1] <= y2[k]) {
          mf.add_edge(i, j + nx, 1LL << 50);
          break;
        }
      }
    }
  }
  cout << mf.max_flow() << endl;
}