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 FordFulkerson {
  vector<vector<int> > cap;
  vector<vector<int> > adj;
  vector<int> prev;
  FordFulkerson(int n) {
    cap.resize(n);
    for (int i = 0; i < n; i++) cap[i].resize(n);
    adj.resize(n);
  }
  void add_edge(int u, int v, int w) {
    cap[u][v] += w;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int bfs(int s, int t) {
    prev = vector<int>(int(cap.size()), -1);
    queue<pair<int, int> > q;
    q.push(pair<int, int>(s, 1e9));
    while (not q.empty()) {
      auto [u, f] = q.front();
      if (u == t) return f;
      q.pop();
      for (int v : adj[u]) {
        int c = cap[u][v];
        if (prev[v] == -1 and c > 0) {
          prev[v] = u;
          q.push(pair<int, int>(v, min(f, c)));
        }
      }
    }
    return 0;
  }
  void update(int s, int t, int f) {
    while (t != s) {
      int p = prev[t];
      cap[p][t] -= f;
      cap[t][p] += f;
      t = p;
    }
  }
  int max_flow(int s, int t) {
    int flow = 0;
    while (true) {
      int nflow = bfs(s, t);
      if (nflow == 0) break;
      flow += nflow;
      update(s, t, nflow);
    }
    return flow;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> x1(m);
  vector<int> y1(m);
  vector<int> x2(m);
  vector<int> y2(m);
  vector<int> x, y;
  x.reserve(4 * m);
  y.reserve(4 * m);
  for (int i = 0; i < m; i++) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    x1[i] -= 1;
    y1[i] -= 1;
    x.push_back(x1[i]);
    x.push_back(x2[i]);
    y.push_back(y1[i]);
    y.push_back(y2[i]);
  }
  if (m == 0) {
    cout << 0 << '\n';
    return (0);
  }
  sort(begin(x), end(x));
  x.erase(unique(begin(x), end(x)), end(x));
  sort(begin(y), end(y));
  y.erase(unique(begin(y), end(y)), end(y));
  int z1 = int(x.size()) - 1;
  int z2 = int(y.size()) - 1;
  int s = z1 + z2;
  int t = s + 1;
  FordFulkerson ffa(t + 1);
  for (int i = 0; i < z1; i++) {
    ffa.add_edge(s, i, x[i + 1] - x[i]);
  }
  for (int i = 0; i < z2; i++) {
    ffa.add_edge(z1 + i, t, y[i + 1] - y[i]);
  }
  for (int i = 0; i < z1; i++) {
    for (int j = 0; j < z2; j++) {
      bool add = false;
      for (int k = 0; k < m and not add; k++) {
        if (x1[k] <= x[i] and x[i + 1] <= x2[k] and y1[k] <= y[j] and
            y[j + 1] <= y2[k])
          add = true;
      }
      if (add) ffa.add_edge(i, z1 + j, 2e9);
    }
  }
  cout << ffa.max_flow(s, t) << '\n';
  return (0);
}