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>
#pragma GCC optimize("O3")
using namespace std;
int n, m;
const int maxN = 55;
int x1[maxN], gogoggogogojs[maxN], x2[maxN], y2[maxN];
const int MAXN = 550;
const long long INF = 1e18;
struct edge {
  int a, b;
  long long cap, flow;
};
int s, t, d[MAXN], ptr[MAXN], q[MAXN];
vector<edge> e;
vector<int> g[MAXN];
void add_edge(int a, int b, long long 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);
}
bool bfs() {
  int qh = 0, qt = 0;
  q[qt++] = s;
  memset(d, -1, sizeof d);
  d[s] = 0;
  while (qh < qt && d[t] == -1) {
    int v = q[qh++];
    for (size_t i = 0; i < g[v].size(); ++i) {
      int id = g[v][i], 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;
}
long long dfs(int v, long long 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]], 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;
}
long long dinic() {
  int flow = 0;
  for (;;) {
    if (!bfs()) break;
    memset(ptr, 0, sizeof ptr);
    while (int pushed = dfs(s, INF)) flow += pushed;
  }
  return flow;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  vector<int> byX, byY;
  byX.push_back(1);
  byX.push_back(n + 1);
  byY.push_back(1);
  byY.push_back(n + 1);
  for (int i = 1; i <= m; i++) {
    cin >> x1[i] >> gogoggogogojs[i] >> x2[i] >> y2[i];
    byX.push_back(x1[i]);
    byX.push_back(x2[i] + 1);
    byY.push_back(gogoggogogojs[i]);
    byY.push_back(y2[i] + 1);
  }
  sort(byX.begin(), byX.end());
  byX.erase(unique(byX.begin(), byX.end()), byX.end());
  sort(byY.begin(), byY.end());
  byY.erase(unique(byY.begin(), byY.end()), byY.end());
  int Xsz = byX.size();
  int Ysz = byY.size();
  for (int i = 0; i + 1 < byX.size(); i++) {
    for (int j = 0; j + 1 < byY.size(); j++) {
      int xa = byX[i];
      int xb = byX[i + 1] - 1;
      int ya = byY[j];
      int yb = byY[j + 1] - 1;
      for (int k = 1; k <= m; k++) {
        if (x1[k] <= xa && xb <= x2[k] && gogoggogogojs[k] <= ya &&
            yb <= y2[k]) {
          add_edge(i + 1, Xsz + j + 1, 1e15);
          break;
        }
      }
    }
  }
  s = 0;
  t = Xsz + Ysz + 1;
  for (int i = 0; i + 1 < Xsz; i++) {
    add_edge(0, i + 1, byX[i + 1] - byX[i]);
  }
  for (int i = 0; i + 1 < Ysz; i++) {
    add_edge(i + Xsz + 1, t, byY[i + 1] - byY[i]);
  }
  cout << dinic();
  return 0;
}