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 MAXM = 105;
const int MAXN = 405;
const int inf = 1e9 + 5;
struct Rectangle {
  int r1, c1;
  int r2, c2;
  Rectangle() {}
  Rectangle(int r1, int c1, int r2, int c2) {
    this->r1 = r1;
    this->r2 = r2;
    this->c1 = c1;
    this->c2 = c2;
  }
  bool isInside(Rectangle other) {
    if (this->r1 <= other.r1 && other.r2 <= this->r2 && this->c1 <= other.c1 &&
        other.c2 <= this->c2) {
      return true;
    }
    return false;
  }
};
struct Edge {
  int u, v, val;
  Edge() {}
  Edge(int u, int v, int val) {
    this->u = u;
    this->v = v;
    this->val = val;
  }
};
bool operator<(const Edge A, const Edge B) {
  if (A.val != B.val) return A.val < B.val;
  if (A.u != B.u) return A.u < B.u;
  if (A.v != B.v) return A.v < B.v;
}
struct maxFlowGraph {
  int dist[MAXN];
  int startInd[MAXN];
  vector<Edge> edges;
  vector<int> graph[MAXN];
  maxFlowGraph() {}
  void addEdge(int u, int v, int val) {
    edges.push_back(Edge(u, v, val));
    edges.push_back(Edge(v, u, 0));
    graph[u].push_back(edges.size() - 2);
    graph[v].push_back(edges.size() - 1);
  }
  void BFS(int x) {
    queue<int> q;
    memset(dist, 0, sizeof(dist));
    q.push(x);
    dist[x] = 1;
    while (q.empty() == false) {
      x = q.front();
      q.pop();
      for (int ind : graph[x]) {
        Edge e = edges[ind];
        if (dist[e.v] == 0 && e.val > 0) {
          q.push(e.v);
          dist[e.v] = dist[x] + 1;
        }
      }
    }
  }
  int DFS(int x, int minVal, int sink) {
    if (x == sink) return minVal;
    for (int i = startInd[x]; i < int(graph[x].size()); i++) {
      Edge e = edges[graph[x][i]];
      if (e.val > 0 && dist[e.v] == dist[x] + 1) {
        int flow = DFS(e.v, min(minVal, e.val), sink);
        if (flow != 0) {
          edges[graph[x][i]].val -= flow;
          edges[graph[x][i] ^ 1].val += flow;
          return flow;
        }
      }
      startInd[x]++;
    }
    return 0;
  }
  int calcFlow(int source, int sink) {
    int maxFlow = 0;
    while (true) {
      BFS(source);
      if (dist[sink] == 0) break;
      while (true) {
        int flow = DFS(source, inf, sink);
        if (flow == 0) break;
        maxFlow += flow;
      }
      memset(startInd, 0, sizeof(startInd));
    }
    return maxFlow;
  }
};
vector<int> rows, cols;
bool isImportant[MAXM][MAXM];
vector<Edge> edges;
int colNode[MAXM], rowNode[MAXM], source = 1, sink = 2;
void readAndInit() {
  set<int> sr, sc;
  int n, m;
  cin >> n >> m;
  vector<Rectangle> rects;
  for (int i = 0; i < m; i++) {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    r1--;
    c1--;
    sr.insert(r1);
    sr.insert(r2);
    sc.insert(c1);
    sc.insert(c2);
    rects.push_back(Rectangle(r1, c1, r2, c2));
  }
  for (int row : sr) {
    rows.push_back(row);
  }
  for (int col : sc) {
    cols.push_back(col);
  }
  for (int i = 0; i < int(rows.size()) - 1; i++) {
    for (int j = 0; j < int(cols.size()) - 1; j++) {
      bool ok = false;
      for (Rectangle r : rects) {
        if (r.isInside(Rectangle(rows[i], cols[j], rows[i + 1], cols[j + 1])) ==
            true) {
          ok = true;
          break;
        }
      }
      if (ok == true) {
        isImportant[i][j] = true;
      }
    }
  }
}
maxFlowGraph G;
void buildGraph() {
  int node = 3;
  for (int i = 0; i < int(rows.size()) - 1; i++) {
    rowNode[i] = node;
    node++;
    G.addEdge(source, rowNode[i], rows[i + 1] - rows[i]);
  }
  for (int j = 0; j < int(cols.size()) - 1; j++) {
    colNode[j] = node;
    node++;
    G.addEdge(colNode[j], sink, cols[j + 1] - cols[j]);
  }
  for (int i = 0; i < int(rows.size()) - 1; i++) {
    for (int j = 0; j < int(cols.size()) - 1; j++) {
      if (isImportant[i][j] == true) {
        G.addEdge(rowNode[i], colNode[j], inf);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  readAndInit();
  buildGraph();
  cout << G.calcFlow(source, sink) << '\n';
}