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;
const ll INF = 1e18;
struct MaxFlow {
  struct edge {
    int a, b;
    ll c;
  };
  vector<edge> es;
  vector<vector<int>> g;
  vector<int> d, pt;
  MaxFlow(int n) : g(n + 1), d(n + 1), pt(n + 1) {}
  void addEdge(int a, int b, ll c = INF) {
    es.push_back({a, b, c});
    g[a].push_back((int)es.size() - 1);
    es.push_back({b, a, 0});
    g[b].push_back((int)es.size() - 1);
  }
  bool bfs(int source, int sink) {
    queue<int> q({source});
    fill(d.begin(), d.end(), (int)g.size() + 1);
    d[source] = 0;
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      if (x == sink) break;
      for (int k : g[x]) {
        edge& e = es[k];
        if (e.c > 0 && d[e.b] > d[e.a] + 1) {
          d[e.b] = d[e.a] + 1;
          q.push(e.b);
        }
      }
    }
    return d[sink] != (int)g.size() + 1;
  }
  ll flow(int x, int sink, ll fl = INF) {
    if (x == sink || fl == 0) return fl;
    for (int& i = pt[x]; i < (int)g[x].size(); i++) {
      edge& e = es[g[x][i]];
      edge& oe = es[g[x][i] ^ 1];
      if (d[e.b] == d[e.a] + 1) {
        if (ll pf = flow(e.b, sink, min(e.c, fl))) {
          e.c -= pf;
          oe.c += pf;
          return pf;
        }
      }
    }
    return 0;
  }
  ll getMaxFlow(int source, int sink) {
    ll r = 0;
    while (bfs(source, sink)) {
      fill(pt.begin(), pt.end(), 0);
      while (ll t = flow(source, sink)) r += t;
    }
    return r;
  }
};
int bins(const vector<int>& vec, int val) {
  int low = 0;
  int high = vec.size();
  while (low != high) {
    int mid = (low + high) >> 1;
    if (vec[mid] < val)
      low = mid + 1;
    else
      high = mid;
  }
  return low;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> xs(m);
  vector<pair<int, int>> ys(m);
  vector<int> xev(2 * m);
  vector<int> yev(2 * m);
  for (int i = 0; i < m; ++i) {
    cin >> xs[i].first >> ys[i].first >> xs[i].second >> ys[i].second;
    ++xs[i].second;
    ++ys[i].second;
    xev[2 * i] = xs[i].first;
    xev[2 * i + 1] = xs[i].second;
    yev[2 * i] = ys[i].first;
    yev[2 * i + 1] = ys[i].second;
  }
  sort(xev.begin(), xev.end());
  sort(yev.begin(), yev.end());
  xev.erase(unique(xev.begin(), xev.end()), xev.end());
  yev.erase(unique(yev.begin(), yev.end()), yev.end());
  for (int i = 0; i < m; ++i) {
    xs[i].first = bins(xev, xs[i].first);
    xs[i].second = bins(xev, xs[i].second);
    ys[i].first = bins(yev, ys[i].first);
    ys[i].second = bins(yev, ys[i].second);
  }
  n = xev.size() + yev.size() + 2;
  int source = n - 2;
  int sink = n - 1;
  MaxFlow mf(n);
  for (int i = 0; i < m; ++i) {
    for (int a = xs[i].first; a < xs[i].second; ++a) {
      for (int b = ys[i].first; b < ys[i].second; ++b) {
        mf.addEdge(a, b + xev.size());
      }
    }
  }
  for (int i = 0; i + 1 < xev.size(); ++i) {
    mf.addEdge(source, i, xev[i + 1] - xev[i]);
  }
  for (int i = 0; i + 1 < yev.size(); ++i) {
    mf.addEdge(i + xev.size(), sink, yev[i + 1] - yev[i]);
  }
  ll res = mf.getMaxFlow(source, sink);
  cout << res << '\n';
}