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;
long long n, m;
long long ux[500 << 2], uy[500 << 2];
long long uxn, uyn;
long long s, t, ans;
long long d[500], l, r, q[500];
long long cnt = 1, hd[500];
pair<pair<long long, long long>, pair<long long, long long> > a[500];
struct Node {
  long long nx, to, dis;
} e[500 * 500 * 4];
inline long long read() {
  long long xx = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) xx = (xx << 1) + (xx << 3) + (c ^ 48), c = getchar();
  return f ? -xx : xx;
}
inline long long mn(long long u, long long v) { return u < v ? u : v; }
inline void add(long long u, long long v, long long w) {
  e[++cnt].to = v;
  e[cnt].nx = hd[u];
  e[cnt].dis = w;
  hd[u] = cnt;
}
inline long long bfs() {
  memset(d, 0, sizeof(d));
  d[s] = 1;
  q[l = r = 1] = s;
  while (l <= r) {
    long long u = q[l++];
    for (register int i = hd[u]; i; i = e[i].nx) {
      long long to = e[i].to;
      if (e[i].dis && !d[to]) q[++r] = to, d[to] = d[u] + 1;
    }
  }
  return d[t];
}
inline long long dfs(long long u, long long limit) {
  if (u == t) return limit;
  long long flow = 0;
  for (register int i = hd[u]; i && limit; i = e[i].nx) {
    long long to = e[i].to;
    if (d[to] == d[u] + 1 && e[i].dis) {
      long long fj = dfs(to, mn(limit, e[i].dis));
      e[i].dis -= fj;
      e[i ^ 1].dis += fj;
      flow += fj;
      limit -= fj;
    }
  }
  if (!flow) d[u] = 0;
  return flow;
}
int main() {
  n = read();
  m = read();
  for (register int i = 1; i <= m; ++i) {
    a[i].first.first = read();
    a[i].first.second = read();
    a[i].second.first = read();
    a[i].second.second = read();
    ++a[i].second.first;
    ++a[i].second.second;
    ux[++uxn] = a[i].first.first;
    uy[++uyn] = a[i].first.second;
    ux[++uxn] = a[i].second.first;
    uy[++uyn] = a[i].second.second;
  }
  ux[++uxn] = n + 1, uy[++uyn] = n + 1;
  sort(ux + 1, ux + uxn + 1);
  sort(uy + 1, uy + uyn + 1);
  uxn = unique(ux + 1, ux + uxn + 1) - ux - 1;
  uyn = unique(uy + 1, uy + uyn + 1) - uy - 1;
  s = 0, t = uxn + uyn + 1;
  for (register int i = 1; i <= m; ++i) {
    a[i].first.first = lower_bound(ux + 1, ux + uxn + 1, a[i].first.first) - ux;
    a[i].first.second =
        lower_bound(uy + 1, uy + uyn + 1, a[i].first.second) - uy;
    a[i].second.first =
        lower_bound(ux + 1, ux + uxn + 1, a[i].second.first) - ux;
    a[i].second.second =
        lower_bound(uy + 1, uy + uyn + 1, a[i].second.second) - uy;
    for (register int j = a[i].first.first; j < a[i].second.first; ++j)
      for (register int k = a[i].first.second; k < a[i].second.second; ++k)
        add(j, k + uxn, 1000000000000), add(k + uxn, j, 0);
  }
  for (register int i = 1; i < uxn; ++i)
    add(s, i, ux[i + 1] - ux[i]), add(i, s, 0);
  for (register int i = 1; i < uyn; ++i)
    add(i + uxn, t, uy[i + 1] - uy[i]), add(t, i + uxn, 0);
  while (bfs()) ans += dfs(s, 1000000000000);
  printf("%lld\n", ans);
  return 0;
}