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;
struct Edge {
  int dest, back;
  long long f, c;
};
struct PushRelabel {
  vector<vector<Edge>> g;
  vector<long long> ec;
  vector<Edge*> cur;
  vector<vector<int>> hs;
  vector<int> H;
  PushRelabel(int n) : g(n), ec(n), cur(n), hs(2 * n), H(n) {}
  void add_edge(int s, int t, long long cap, long long rcap = 0) {
    if (s == t) return;
    Edge a = {t, (int)(g[t]).size(), 0, cap};
    Edge b = {s, (int)(g[s]).size(), 0, rcap};
    g[s].push_back(a);
    g[t].push_back(b);
  }
  void add_flow(Edge& e, long long f) {
    Edge& back = g[e.dest][e.back];
    if (!ec[e.dest] && f) hs[H[e.dest]].push_back(e.dest);
    e.f += f;
    e.c -= f;
    ec[e.dest] += f;
    back.f -= f;
    back.c += f;
    ec[back.dest] -= f;
  }
  long long maxflow(int s, int t) {
    int v = (int)(g).size();
    H[s] = v;
    ec[t] = 1;
    vector<int> co(2 * v);
    co[0] = v - 1;
    for (int i = 0; i < (v); ++i) cur[i] = g[i].data();
    for (auto& e : g[s]) add_flow(e, e.c);
    for (int hi = 0;;) {
      while (hs[hi].empty())
        if (!hi--) return -ec[s];
      int u = hs[hi].back();
      hs[hi].pop_back();
      while (ec[u] > 0)
        if (cur[u] == g[u].data() + (int)(g[u]).size()) {
          H[u] = 1e9;
          for (auto& e : g[u])
            if (e.c && H[u] > H[e.dest] + 1) H[u] = H[e.dest] + 1, cur[u] = &e;
          if (++co[H[u]], !--co[hi] && hi < v)
            for (int i = 0; i < (v); ++i)
              if (hi < H[i] && H[i] < v) --co[H[i]], H[i] = v + 1;
          hi = H[u];
        } else if (cur[u]->c && H[u] == H[cur[u]->dest] + 1)
          add_flow(*cur[u], min(ec[u], cur[u]->c));
        else
          ++cur[u];
    }
  }
};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> xa(m), xb(m), ya(m), yb(m);
  set<int> xv, yv;
  for (int i = 0; i < m; i++) {
    cin >> xa[i] >> ya[i] >> xb[i] >> yb[i];
    xa[i]--;
    ya[i]--;
    xv.insert(xa[i]);
    xv.insert(xb[i]);
    yv.insert(ya[i]);
    yv.insert(yb[i]);
  }
  xv.insert(0);
  xv.insert(n);
  yv.insert(0);
  yv.insert(n);
  vector<int> xl, yl;
  for (int x : xv) {
    xl.push_back(x);
  }
  for (int y : yv) {
    yl.push_back(y);
  }
  int a = (int)xl.size() - 1;
  int b = (int)yl.size() - 1;
  PushRelabel flow(a + b + 2);
  for (int i = 0; i < a; i++) {
    flow.add_edge(a + b, i, xl[i + 1] - xl[i]);
  }
  for (int i = 0; i < b; i++) {
    flow.add_edge(i + a, a + b + 1, yl[i + 1] - yl[i]);
  }
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      bool needs = false;
      for (int c = 0; c < m; c++) {
        if (xl[i + 1] <= xa[c] || xb[c] <= xl[i]) continue;
        if (yl[j + 1] <= ya[c] || yb[c] <= yl[j]) continue;
        needs = true;
      }
      if (needs) {
        flow.add_edge(i, j + a, 1e16);
      }
    }
  }
  cout << flow.maxflow(a + b, a + b + 1) << '\n';
}