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 INF = 1e9 + 7;
struct rect {
  int x1, y1, x2, y2;
};
struct Edge {
  int a, b, cap, flow;
};
struct MaxFlow {
  int n, s, t;
  vector<int> d, ptr, q;
  vector<Edge> e;
  vector<vector<int> > g;
  MaxFlow(int n) : n(n), d(n), ptr(n), q(n), g(n) {
    e.clear();
    for (int i = 0; i < n; i++) {
      g[i].clear();
      ptr[i] = 0;
    }
  }
  void addEdge(int a, int b, int cap) {
    Edge e1 = {a, b, cap, 0};
    Edge e2 = {b, a, 0, 0};
    g[a].push_back((int)e.size());
    e.push_back(e1);
    g[b].push_back((int)e.size());
    e.push_back(e2);
  }
  int getMaxFlow(int _s, int _t) {
    s = _s;
    t = _t;
    int flow = 0;
    for (;;) {
      if (!bfs()) break;
      for (int i = 0; i < n; i++) ptr[i] = 0;
      while (int pushed = dfs(s, INF)) flow += pushed;
    }
    return flow;
  }

 private:
  bool bfs() {
    int qh = 0;
    int qt = 0;
    q[qt++] = s;
    for (int i = 0; i < n; i++) d[i] = -1;
    d[s] = 0;
    while (qh < qt && d[t] == -1) {
      int v = q[qh++];
      for (int i = 0; i < g[v].size(); i++) {
        int id = g[v][i];
        int to = e[id].b;
        if (d[to] == -1 && e[id].flow < e[id].cap) {
          q[qt++] = to;
          d[to] = d[v] + 1;
        }
      }
    }
    return d[t] != -1;
  }
  int dfs(int v, int flow) {
    if (!flow) return 0;
    if (v == t) return flow;
    for (; ptr[v] < (int)g[v].size(); ++ptr[v]) {
      int id = g[v][ptr[v]];
      int to = e[id].b;
      if (d[to] != d[v] + 1) continue;
      int pushed = dfs(to, min(flow, e[id].cap - e[id].flow));
      if (pushed) {
        e[id].flow += pushed;
        e[id ^ 1].flow -= pushed;
        return pushed;
      }
    }
    return 0;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<rect> e;
  vector<int> rs, cs;
  for (int i = 0; i < m; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    e.push_back({x1, y1, x2, y2});
    rs.push_back(x1), rs.push_back(x2 + 1);
    cs.push_back(y1), cs.push_back(y2 + 1);
  }
  sort(rs.begin(), rs.end());
  rs.resize(unique(rs.begin(), rs.end()) - rs.begin());
  sort(cs.begin(), cs.end());
  cs.resize(unique(cs.begin(), cs.end()) - cs.begin());
  int s = rs.size() + cs.size();
  int t = rs.size() + cs.size() + 1;
  MaxFlow ans(t + 1);
  for (int i = 0; i + 1 < (int)rs.size(); i++) {
    ans.addEdge(s, i, rs[i + 1] - rs[i]);
  }
  for (int i = 0; i + 1 < (int)cs.size(); i++) {
    ans.addEdge(i + rs.size(), t, cs[i + 1] - cs[i]);
  }
  for (int i = 0; i < e.size(); i++) {
    rect c = e[i];
    for (int i = 0; i + 1 < (int)rs.size(); i++) {
      if (c.x1 <= rs[i] && rs[i + 1] - 1 <= c.x2) {
        for (int j = 0; j + 1 < (int)cs.size(); j++) {
          if (c.y1 <= cs[j] && cs[j + 1] - 1 <= c.y2) {
            ans.addEdge(i, rs.size() + j, INF);
          }
        }
      }
    }
  }
  cout << ans.getMaxFlow(s, t) << '\n';
}