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;
namespace dinic {
using ll = int;
const ll oo = 1e9;
const int N = 2005;
const int E = 2000006;
vector<int> g[N];
int ne;
struct Edge {
  int from, to;
  ll flow, cap;
} edge[E];
int lvl[N], vis[N], pass, start = N - 2, target = N - 1;
int qu[N], qt, px[N];
ll run(int s, int sink, ll minE) {
  if (s == sink) return minE;
  ll ans = 0;
  for (; px[s] < (int)g[s].size(); px[s]++) {
    int e = g[s][px[s]];
    auto &v = edge[e], &rev = edge[e ^ 1];
    if (lvl[v.to] != lvl[s] + 1 || v.flow >= v.cap) continue;
    ll tmp = run(v.to, sink, min(minE, v.cap - v.flow));
    v.flow += tmp, rev.flow -= tmp;
    ans += tmp, minE -= tmp;
    if (minE == 0) break;
  }
  return ans;
}
bool bfs(int source, int sink) {
  qt = 0;
  qu[qt++] = source;
  lvl[source] = 1;
  vis[source] = ++pass;
  for (int i = 0; i < qt; i++) {
    int u = qu[i];
    px[u] = 0;
    if (u == sink) return true;
    for (auto &ed : g[u]) {
      auto v = edge[ed];
      if (v.flow >= v.cap || vis[v.to] == pass) continue;
      vis[v.to] = pass;
      lvl[v.to] = lvl[u] + 1;
      qu[qt++] = v.to;
    }
  }
  return false;
}
ll flow(int source = start, int sink = target) {
  ll ans = 0;
  while (bfs(source, sink)) ans += run(source, sink, oo);
  return ans;
}
void addEdge(int u, int v, ll c = 1, ll rc = 0) {
  edge[ne] = {u, v, 0, c};
  g[u].push_back(ne++);
  edge[ne] = {v, u, 0, rc};
  g[v].push_back(ne++);
}
}  // namespace dinic
const int N = 55;
void relax(vector<pair<int, int>> &vec, int l, int r) {
  for (int i = 0; i < (int)vec.size(); i++) {
    if (vec[i].first <= l and l <= vec[i].second) {
      if (vec[i].first < l) {
        int rig = vec[i].second;
        vec[i].second = l - 1;
        vec.push_back({l, rig});
        sort(vec.begin(), vec.end());
      }
      break;
    }
  }
  for (int i = 0; i < (int)vec.size(); i++) {
    if (vec[i].first <= r and r <= vec[i].second) {
      if (r < vec[i].second) {
        int lef = vec[i].first;
        vec[i].first = r + 1;
        vec.push_back({lef, r});
        sort(vec.begin(), vec.end());
      }
      break;
    }
  }
}
vector<int> get(const vector<pair<int, int>> &vec, int l, int r) {
  vector<int> ans;
  for (int i = 0; i < (int)vec.size(); i++) {
    if (l <= vec[i].first and vec[i].second <= r) {
      ans.push_back(i);
    }
  }
  return ans;
}
int n, m;
int a[N], b[N], c[N], d[N];
int main() {
  scanf("%d %d", &n, &m);
  vector<pair<int, int>> vx, vy;
  vx.push_back({1, n});
  vy.push_back({1, n});
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d %d", a + i, b + i, c + i, d + i);
    relax(vx, a[i], c[i]);
    relax(vy, b[i], d[i]);
  }
  for (int i = 0; i < m; i++) {
    auto x = get(vx, a[i], c[i]);
    auto y = get(vy, b[i], d[i]);
    for (int valx : x)
      for (int valy : y) {
        dinic::addEdge(valx, (int)vx.size() + valy, dinic::oo);
      }
  }
  for (int i = 0; i < (int)vx.size(); i++) {
    int len = vx[i].second - vx[i].first + 1;
    dinic::addEdge(dinic::start, i, len);
  }
  for (int i = 0; i < (int)vy.size(); i++) {
    int len = vy[i].second - vy[i].first + 1;
    dinic::addEdge((int)vx.size() + i, dinic::target, len);
  }
  int ans = dinic::flow();
  printf("%d\n", ans);
}