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 long long inf = 1e15 + 7;
struct Dinic {
  long long n, s, t;
  struct Edge {
    long long to, cap, flow, rev;
    Edge(long long to = 0, long long cap = 0, long long flow = 0,
         long long rev = 0)
        : to(to), cap(cap), flow(flow), rev(rev) {}
  };
  vector<long long> d;
  vector<long long> ptr;
  vector<vector<Edge>> g;
  Dinic(long long n = 0, long long s = 0, long long t = 0)
      : n(n), s(s), t(t), d(n + 2), ptr(n + 2), g(n + 2) {}
  void addEdge(long long u, long long v, long long cap) {
    g[u].emplace_back(v, cap, 0, g[v].size());
    g[v].emplace_back(u, 0, 0, g[u].size() - 1);
  }
  bool bfs() {
    fill(d.begin(), d.end(), -1);
    fill(ptr.begin(), ptr.end(), 0);
    queue<long long> q;
    d[s] = 0;
    q.push(s);
    while (!q.empty()) {
      long long u = q.front();
      q.pop();
      for (auto e : g[u]) {
        if (d[e.to] == -1 && e.cap > e.flow) {
          d[e.to] = d[u] + 1;
          q.push(e.to);
        }
      }
    }
    return d[t] != -1;
  }
  long long dfs(long long u, long long flow) {
    if (u == t) {
      return flow;
    }
    for (long long &i = ptr[u]; i < (long long)g[u].size(); i++) {
      auto &e = g[u][i];
      if (e.cap <= e.flow || d[e.to] != d[u] + 1) continue;
      long long nxt = dfs(e.to, min(flow, e.cap - e.flow));
      if (nxt) {
        e.flow += nxt;
        g[e.to][e.rev].flow -= nxt;
        return nxt;
      }
    }
    return 0;
  }
  long long maxFlow() {
    long long ans = 0;
    while (bfs()) {
      while (true) {
        long long now = dfs(s, inf);
        if (now)
          ans += now;
        else
          break;
      }
    }
    return ans;
  }
};
const long long N = 1e5 + 2;
const long long M = 52;
pair<pair<long long, long long>, pair<long long, long long>> rect[M];
pair<long long, long long> row_lis[N], col_lis[N];
vector<long long> lis, lis1;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, i, j, k, l, m, num_row = 0, num_col = 0, z, t1, z1;
  cin >> n >> m;
  if (m == 0) {
    cout << 0;
    return 0;
  }
  for (i = 1; i <= m; i++) {
    cin >> rect[i].first.first >> rect[i].first.second >>
        rect[i].second.first >> rect[i].second.second;
    lis.push_back(rect[i].first.first - 1);
    lis.push_back(rect[i].second.first);
    lis1.push_back(rect[i].first.second - 1);
    lis1.push_back(rect[i].second.second);
  }
  sort(lis.begin(), lis.end());
  sort(lis1.begin(), lis1.end());
  lis.erase(unique(lis.begin(), lis.end()), lis.end());
  lis1.erase(unique(lis1.begin(), lis1.end()), lis1.end());
  num_row = lis.size() - 1;
  num_col = lis1.size() - 1;
  long long s = num_row + num_col + 1, t = num_row + num_col + 2;
  Dinic dn(num_row + num_col + 2, s, t);
  for (i = 1; i < lis.size(); i++) {
    dn.addEdge(s, i, lis[i] - lis[i - 1]);
  }
  for (i = 1; i < lis1.size(); i++) {
    dn.addEdge(num_row + i, t, lis1[i] - lis1[i - 1]);
  }
  for (i = 1; i <= m; i++) {
    l = lower_bound(lis.begin(), lis.end(), rect[i].first.first - 1) -
        lis.begin();
    z1 =
        lower_bound(lis.begin(), lis.end(), rect[i].second.first) - lis.begin();
    z = lower_bound(lis1.begin(), lis1.end(), rect[i].first.second - 1) -
        lis1.begin();
    t1 = lower_bound(lis1.begin(), lis1.end(), rect[i].second.second) -
         lis1.begin();
    for (j = l + 1; j <= z1; j++) {
      for (k = z + 1; k <= t1; k++) {
        dn.addEdge(j, k + num_row, inf);
      }
    }
  }
  cout << dn.maxFlow();
}