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 int MAXN = 105;
const long long MOD = 1000000007;
const int INF = 2147483647;
template <class T>
struct Dinic {
  static const int maxn = 410 + 10;
  struct Edge {
    int f, to;
    T c;
    Edge(int _f, int _to, T _c) : f(_f), to(_to), c(_c) {}
  };
  vector<int> G[maxn];
  vector<Edge> es;
  int level[maxn], st, end, n;
  int cur[maxn];
  void init(int _n) {
    n = _n;
    es.clear();
    for (int i = 0; i <= n; i++) G[i].clear();
  }
  void addEdge(int f, int t, T c, bool directed) {
    es.push_back(Edge(f, t, c));
    G[f].push_back(es.size() - 1);
    es.push_back(Edge(t, f, directed ? 0 : c));
    G[t].push_back(es.size() - 1);
  }
  bool BFS(int s, int t) {
    queue<int> Q;
    for (int i = 0; i <= n; i++) level[i] = 0;
    level[s] = 1;
    Q.push(s);
    while (!Q.empty()) {
      int x = Q.front();
      Q.pop();
      for (int i = 0; i < G[x].size(); i++) {
        Edge e = es[G[x][i]];
        if (e.c == 0 || level[e.to]) continue;
        level[e.to] = level[x] + 1;
        Q.push(e.to);
      }
    }
    return level[t] != 0;
  }
  T DFS(int s, T cur_flow) {
    if (s == end) return cur_flow;
    T ans = 0, temp, total = 0;
    for (int& i = cur[s]; i < G[s].size(); i++) {
      Edge& e = es[G[s][i]];
      if (e.c == 0 || level[e.to] != level[s] + 1) continue;
      temp = DFS(e.to, min(e.c, cur_flow));
      if (temp != 0) {
        e.c -= temp;
        es[G[s][i] ^ 1].c += temp;
        cur_flow -= temp;
        total += temp;
        if (cur_flow == 0) break;
      }
    }
    return total;
  }
  T maxFlow(int s, int t) {
    T ans = 0;
    st = s, end = t;
    while (BFS(s, t)) {
      while (true) {
        memset(cur, 0, sizeof(cur));
        T temp = DFS(s, INF);
        if (temp == 0) break;
        ans += temp;
      }
    }
    return ans;
  }
};
struct Rec {
  int x1, x2, y1, y2;
};
int N, M;
vector<int> chgx, chgy;
bool adj[MAXN][MAXN];
Rec rec[MAXN];
Dinic<int> algo;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    rec[i] = {x1, x2, y1, y2};
    chgx.push_back(x1);
    if (x2 != N) chgx.push_back(x2 + 1);
    chgy.push_back(y1);
    if (y2 != N) chgy.push_back(y2 + 1);
  }
  chgx.push_back(1);
  chgy.push_back(1);
  sort(chgx.begin(), chgx.end());
  sort(chgy.begin(), chgy.end());
  chgx.resize(unique(chgx.begin(), chgx.end()) - chgx.begin());
  chgy.resize(unique(chgy.begin(), chgy.end()) - chgy.begin());
  int src = 0, tgt = (int)chgx.size() + (int)chgy.size() + 1;
  algo.init(tgt + 1);
  for (int q = 0; q < M; q++) {
    for (int i = 0; i < chgx.size(); i++) {
      for (int j = 0; j < chgy.size(); j++) {
        int x = chgx[i], y = chgy[j];
        if (rec[q].x1 <= x && x <= rec[q].x2) {
          if (rec[q].y1 <= y && y <= rec[q].y2) {
            adj[i][j] = true;
          }
        }
      }
    }
  }
  for (int i = 0; i < chgx.size(); i++) {
    int len = (i + 1 == chgx.size() ? N + 1 : chgx[i + 1]) - chgx[i];
    algo.addEdge(src, i + 1, len, true);
  }
  for (int i = 0; i < chgy.size(); i++) {
    int len = (i + 1 == chgy.size() ? N + 1 : chgy[i + 1]) - chgy[i];
    algo.addEdge(i + chgx.size() + 1, tgt, len, true);
  }
  for (int i = 0; i < chgx.size(); i++) {
    for (int j = 0; j < chgy.size(); j++) {
      if (adj[i][j]) {
        algo.addEdge(i + 1, j + chgx.size() + 1, INF, true);
      }
    }
  }
  cout << algo.maxFlow(src, tgt);
  return 0;
}