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;
inline void read(int &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
inline unsigned int R() {
  static unsigned int seed = 416;
  return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
}
const int N = 1220, M = 240030, inf = 0x3f3f3f3f;
int n, m, S, T, head[N], cur[N], nxt[M], cap[M], to[M], edgenum = 1;
void addedge(int u, int v, int c) {
  to[++edgenum] = v;
  cap[edgenum] = c;
  nxt[edgenum] = head[u];
  head[u] = edgenum;
}
void add(int u, int v, int c) {
  addedge(u, v, c);
  addedge(v, u, 0);
}
int dis[N], q[N];
inline bool bfs() {
  memset(dis, inf, 4 * (T + 2));
  int f = 0, r = 1;
  q[f] = T;
  dis[T] = 0;
  while (f != r) {
    int u = q[f++];
    for (int i = head[u]; i != 0; i = nxt[i])
      if (cap[i ^ 1] && dis[to[i]] == inf) {
        q[r++] = to[i];
        dis[to[i]] = dis[u] + 1;
        if (to[i] == S) return 1;
      }
  }
  return dis[S] < inf;
}
inline int dfs(int u, int flow) {
  if (u == T || !flow) return flow;
  int res = 0;
  for (register int &i = cur[u]; i; i = nxt[i])
    if (cap[i] && dis[u] == dis[to[i]] + 1) {
      int tmp = dfs(to[i], min(flow, cap[i]));
      res += tmp;
      flow -= tmp;
      cap[i] -= tmp;
      cap[i ^ 1] += tmp;
      if (!flow) break;
    }
  return res;
}
inline int dinic() {
  int res = 0;
  while (bfs()) {
    memcpy(cur, head, 4 * (T + 2));
    res += dfs(S, inf);
  }
  return res;
}
int a[N], la, b[N], lb, A[N], B[N], C[N], D[N];
int main() {
  read(n);
  read(m);
  for (register int i = 1; i <= m; i++) {
    read(A[i]);
    read(B[i]);
    read(C[i]);
    read(D[i]);
    a[++la] = A[i];
    a[++la] = C[i] + 1;
    b[++lb] = B[i];
    b[++lb] = D[i] + 1;
  }
  sort(a + 1, a + la + 1);
  la = unique(a + 1, a + la + 1) - a - 1;
  sort(b + 1, b + lb + 1);
  lb = unique(b + 1, b + lb + 1) - b - 1;
  S = la + lb + m + 1;
  T = S + 1;
  for (register int i = 1; i <= la - 1; i++) add(S, i, a[i + 1] - a[i]);
  for (register int i = 1; i <= lb - 1; i++) add(la + i, T, b[i + 1] - b[i]);
  for (register int i = 1; i <= m; i++) {
    int l = lower_bound(a + 1, a + la + 1, A[i]) - a;
    int r = lower_bound(a + 1, a + la + 1, C[i] + 1) - a;
    for (register int j = l; j <= r - 1; j++) add(j, la + lb + i, inf);
    l = lower_bound(b + 1, b + lb + 1, B[i]) - b;
    r = lower_bound(b + 1, b + lb + 1, D[i] + 1) - b;
    for (register int j = l; j <= r - 1; j++) add(la + lb + i, la + j, inf);
  }
  cout << dinic();
  return 0;
}