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;
int xx1[52], yy1[52], xx2[52], yy2[52];
vector<int> X, Y;
struct Edge {
  int u, v;
  int cap, flow;
  Edge() {}
  Edge(int u, int v, int cap) : u(u), v(v), cap(cap), flow(0) {}
};
struct Dinic {
  int N;
  vector<Edge> E;
  vector<vector<int>> g;
  vector<int> d, pt;
  Dinic(int N) : N(N), E(0), g(N), d(N), pt(N) {}
  void AddEdge(int u, int v, int cap) {
    if (u != v) {
      E.emplace_back(Edge(u, v, cap));
      g[u].emplace_back(E.size() - 1);
      E.emplace_back(Edge(v, u, 0));
      g[v].emplace_back(E.size() - 1);
    }
  }
  bool bfs(int s, int t) {
    queue<int> q({s});
    fill(d.begin(), d.end(), N + 1);
    d[s] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      if (u == t) break;
      for (int k : g[u]) {
        Edge &e = E[k];
        if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
          d[e.v] = d[e.u] + 1;
          q.emplace(e.v);
        }
      }
    }
    return d[t] != N + 1;
  }
  int dfs(int u, int t, int f = -1) {
    if (u == t || f == 0) return f;
    for (int &i = pt[u]; i < g[u].size(); ++i) {
      Edge &e = E[g[u][i]];
      Edge &oe = E[g[u][i] ^ 1];
      if (d[e.v] == d[e.u] + 1) {
        int amt = e.cap - e.flow;
        if (f != -1 && amt > f) amt = f;
        if (int pushed = dfs(e.v, t, amt)) {
          e.flow += pushed;
          oe.flow -= pushed;
          return pushed;
        }
      }
    }
    return 0;
  }
  int MaxFlow(int s, int t) {
    int total = 0;
    while (bfs(s, t)) {
      fill(pt.begin(), pt.end(), 0);
      while (int f = dfs(s, t)) total += f;
    }
    return total;
  }
};
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &xx1[i], &yy1[i], &xx2[i], &yy2[i]);
    xx2[i]++, yy2[i]++;
    X.emplace_back(xx1[i]);
    X.emplace_back(xx2[i]);
    Y.emplace_back(yy1[i]);
    Y.emplace_back(yy2[i]);
  }
  sort(X.begin(), X.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  sort(Y.begin(), Y.end());
  Y.erase(unique(Y.begin(), Y.end()), Y.end());
  Dinic dinic(X.size() + Y.size() + 2);
  int s = 0, t = X.size() + Y.size() + 1;
  for (int i = 0; i < X.size(); i++) {
    if (i != X.size() - 1) dinic.AddEdge(s, i + 1, X[i + 1] - X[i]);
  }
  for (int i = 0; i < Y.size(); i++) {
    if (i != Y.size() - 1) dinic.AddEdge(X.size() + i + 1, t, Y[i + 1] - Y[i]);
  }
  for (int i = 1; i <= m; i++) {
    int lx = lower_bound(X.begin(), X.end(), xx1[i]) - X.begin();
    int rx = lower_bound(X.begin(), X.end(), xx2[i]) - X.begin() - 1;
    int ly = lower_bound(Y.begin(), Y.end(), yy1[i]) - Y.begin();
    int ry = lower_bound(Y.begin(), Y.end(), yy2[i]) - Y.begin() - 1;
    for (int i = lx; i <= rx; i++) {
      for (int j = ly; j <= ry; j++)
        dinic.AddEdge(i + 1, X.size() + j + 1, 1e9);
    }
  }
  printf("%d\n", dinic.MaxFlow(s, t));
}