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 long long INF = 1ll << 60;
struct Dinic {
  struct Edge {
    int v, id;
    long long f;
    Edge(int _v, long long _f, int _id) : v(_v), id(_id), f(_f) {}
  };
  vector<vector<Edge>> adj;
  vector<int> level;
  int n, s, t;
  Dinic(int _n, int _s, int _t) : n(_n), s(_s), t(_t) {
    adj.resize(n);
    level.resize(n);
  }
  void add_edge(int u, int v, long long f) {
    adj[u].push_back(Edge(v, f, adj[v].size()));
    adj[v].push_back(Edge(u, 0, adj[u].size() - 1));
  }
  bool bfs() {
    for (int i = 0; i < n; ++i) level[i] = -1;
    queue<int> q;
    q.push(s);
    level[s] = 0;
    while (q.size()) {
      int v = q.front();
      q.pop();
      for (Edge e : adj[v]) {
        if (e.f > 0 and level[e.v] == -1) {
          level[e.v] = level[v] + 1;
          q.push(e.v);
        }
      }
    }
    return level[t] != -1;
  }
  long long dfs(int v, long long minf) {
    if (v == t) return minf;
    long long ans = 0;
    for (Edge &e : adj[v]) {
      if (e.f > 0 and level[e.v] == level[v] + 1) {
        long long nxtf = dfs(e.v, min(minf, e.f));
        ans += nxtf;
        minf -= nxtf;
        e.f -= nxtf;
        adj[e.v][e.id].f += nxtf;
        if (minf == 0) return ans;
      }
    }
    if (!ans) level[v] = -1;
    return ans;
  }
  long long runFlow() {
    long long ans = 0;
    while (bfs()) {
      ans += dfs(s, INF);
    }
    return ans;
  }
};
int main() {
  vector<int> l, r;
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << 0 << endl;
    return 0;
  }
  pair<int, int> x[m], y[m];
  for (int i = (0); i < (m); i++) {
    cin >> x[i].first >> y[i].first >> x[i].second >> y[i].second;
    l.push_back(x[i].first);
    l.push_back(x[i].second);
    r.push_back(y[i].first);
    r.push_back(y[i].second);
  }
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  l.resize(unique(l.begin(), l.end()) - l.begin());
  r.resize(unique(r.begin(), r.end()) - r.begin());
  int all = l.size() * 2 + r.size() * 2;
  int s = all - 2, t = all - 1;
  Dinic solver(all, s, t);
  for (int i = (0); i < (l.size()); i++) solver.add_edge(s, i * 2, 1);
  for (int i = (0); i < (l.size() - 1); i++)
    solver.add_edge(s, i * 2 + 1, l[i + 1] - l[i] - 1);
  for (int i = (0); i < (r.size()); i++)
    solver.add_edge(l.size() * 2 - 1 + i * 2, t, 1);
  for (int i = (0); i < (r.size() - 1); i++)
    solver.add_edge(l.size() * 2 + i * 2, t, r[i + 1] - r[i] - 1);
  for (int i = (0); i < (m); i++) {
    int a1 = lower_bound(l.begin(), l.end(), x[i].first) - l.begin();
    int a2 = lower_bound(l.begin(), l.end(), x[i].second) - l.begin();
    int b1 = lower_bound(r.begin(), r.end(), y[i].first) - r.begin();
    int b2 = lower_bound(r.begin(), r.end(), y[i].second) - r.begin();
    for (int a = (a1 * 2); a < (a2 * 2 + 1); a++) {
      for (int b = (b1 * 2); b < (b2 * 2 + 1); b++) {
        solver.add_edge(a, l.size() * 2 - 1 + b, INF);
      }
    }
  }
  cout << solver.runFlow() << endl;
}