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>
inline long long gi() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
long long S, T, fir[210], dep[210], head[210], dis[10000010], nxt[10000010],
    w[10000010], id = 1, cnt;
inline void link(long long a, long long b, long long c) {
  nxt[++id] = fir[a], fir[a] = id, dis[id] = b, w[id] = c;
  nxt[++id] = fir[b], fir[b] = id, dis[id] = a, w[id] = 0;
}
inline bool BFS() {
  static long long que[210], hd, tl;
  memset(dep, 0, sizeof dep);
  hd = tl = 0;
  que[tl++] = S;
  dep[S] = 1;
  while (hd ^ tl) {
    long long x = que[hd++];
    for (long long i = fir[x]; i; i = nxt[i])
      if (!dep[dis[i]] && w[i]) dep[dis[i]] = dep[x] + 1, que[tl++] = dis[i];
  }
  return dep[T];
}
inline long long Dinic(long long x, long long maxflow) {
  if (x == T) return maxflow;
  long long ret = 0;
  for (long long& i = head[x]; i; i = nxt[i])
    if (w[i] && dep[dis[i]] == dep[x] + 1) {
      long long d = Dinic(dis[i], std::min(maxflow - ret, w[i]));
      w[i] -= d, w[i ^ 1] += d, ret += d;
      if (ret == maxflow) break;
    }
  return ret;
}
long long xl[51], xr[51], yl[51], yr[51], ux[101], uy[101], mx, my;
std::set<std::pair<long long, long long>> itst;
signed main() {
  long long n = gi(), m = gi();
  for (long long i = 1; i <= m; ++i) {
    xl[i] = gi(), yl[i] = gi();
    xr[i] = gi(), yr[i] = gi();
    ux[++mx] = xl[i];
    ux[++mx] = xr[i] + 1;
    uy[++my] = yl[i];
    uy[++my] = yr[i] + 1;
  }
  std::sort(ux + 1, ux + mx + 1);
  mx = std::unique(ux + 1, ux + mx + 1) - ux - 1;
  std::sort(uy + 1, uy + my + 1);
  my = std::unique(uy + 1, uy + my + 1) - uy - 1;
  S = mx + my + 1, T = cnt = mx + my + 2;
  for (long long i = 1; i < mx; ++i) link(S, i, ux[i + 1] - ux[i]);
  for (long long i = 1; i < my; ++i) link(i + mx, T, uy[i + 1] - uy[i]);
  for (long long i = 1; i <= m; ++i) {
    xl[i] = std::lower_bound(ux + 1, ux + mx + 1, xl[i]) - ux;
    xr[i] = std::lower_bound(ux + 1, ux + mx + 1, xr[i] + 1) - ux;
    yl[i] = std::lower_bound(uy + 1, uy + my + 1, yl[i]) - uy;
    yr[i] = std::lower_bound(uy + 1, uy + my + 1, yr[i] + 1) - uy;
    for (long long j = xl[i]; j < xr[i]; ++j)
      for (long long k = yl[i]; k < yr[i]; ++k) link(j, k + mx, 1e18);
  }
  long long ans = 0;
  while (BFS()) memcpy(head, fir, sizeof fir), ans += Dinic(S, 1e18);
  printf("%lld\n", ans);
  return 0;
}