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 std::make_pair;
using std::pair;
const int N = 205, INF = 2e9;
struct rt {
  int sx, sy, tx, ty;
} rec[55];
int n, m, cnt1, cnt2, id1, id2, sx, sy, tx, ty;
pair<int, int> a[N], b[N], h[N], l[N];
int dis[N], S, T, to[N * N * 2], edge, Next[N * N * 2], last[N], w[N * N * 2],
    dep[N], ans, f[105][105];
std::queue<int> q;
void add(int x, int y, int ww) {
  to[++edge] = y;
  Next[edge] = last[x];
  last[x] = edge;
  w[edge] = ww;
}
void Add(int x, int y, int ww) { add(x, y, ww), add(y, x, 0); }
int cal(int x) { return (x & 1) ? x + 1 : x - 1; }
bool BFS() {
  memset(dep, 0, sizeof(dep));
  dep[S] = 1;
  q.push(S);
  while (q.size()) {
    int x = q.front();
    q.pop();
    for (int i = last[x]; i; i = Next[i]) {
      int u = to[i];
      if ((!w[i]) || dep[u]) continue;
      dep[u] = dep[x] + 1;
      q.push(u);
    }
  }
  return dep[T];
}
int dfs(int x, int now) {
  if (x == T) return now;
  int sum = 0;
  for (int i = last[x]; i; i = Next[i]) {
    int u = to[i];
    if (w[i] && dep[u] > dep[x]) {
      int di = dfs(u, std::min(now, w[i]));
      w[i] -= di;
      w[cal(i)] += di;
      now -= di;
      sum += di;
    }
  }
  if (sum == 0) dep[x] = 0;
  return sum;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
    rec[i] = {sx, sy, tx, ty};
    a[++cnt1] = make_pair(sx, 1), a[++cnt1] = make_pair(tx + 1, -1);
    b[++cnt2] = make_pair(sy, 1), b[++cnt2] = make_pair(ty + 1, -1);
  }
  std::sort(a + 1, a + cnt1 + 1);
  for (int i = 1, now = 0; i <= cnt1; i++) {
    if (now && a[i - 1].first != a[i].first)
      h[++id1] = make_pair(a[i - 1].first, a[i].first - 1);
    now += a[i].second;
  }
  std::sort(b + 1, b + cnt2 + 1);
  for (int i = 1, now = 0; i <= cnt2; i++) {
    if (now && b[i - 1].first != b[i].first)
      l[++id2] = make_pair(b[i - 1].first, b[i].first - 1);
    now += b[i].second;
  }
  S = id1 + id2 + 1, T = S + 1;
  for (int i = 1; i <= id1; i++) Add(S, i, h[i].second - h[i].first + 1);
  for (int i = 1; i <= id2; i++) Add(i + id1, T, l[i].second - l[i].first + 1);
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= id1 && h[j].second <= rec[i].tx; j++) {
      if (h[j].first < rec[i].sx) continue;
      for (int k = 1; k <= id2 && l[k].second <= rec[i].ty; k++) {
        if (l[k].first < rec[i].sy) continue;
        f[j][k] = 1;
      }
    }
  for (int i = 1; i <= id1; i++)
    for (int j = 1; j <= id2; j++)
      if (f[i][j]) Add(i, j + id1, INF);
  while (BFS())
    while (int di = dfs(S, INF)) ans += di;
  printf("%d\n", ans);
}