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>
int min(int a, int b) { return a < b ? a : b; }
int *xy;
int compare(const void *a, const void *b) {
  int i = *(int *)a;
  int j = *(int *)b;
  return xy[i] - xy[j];
}
int compress(int *xx, int *hh, int *xx_, int n) {
  int h, i;
  xy = xx, qsort(hh, n, sizeof *hh, compare);
  i = 0;
  for (h = 0; h < n; h++)
    if (h + 1 == n || xx[hh[h + 1]] != xx[hh[h]]) {
      xx_[i] = xx[hh[h]];
      xx[hh[h]] = i++;
    } else
      xx[hh[h]] = i;
  return i;
}
int oo[1 + ((50 * 2 - 1) * (50 * 2 - 1) + (50 * 2 - 1) + (50 * 2 - 1)) * 2],
    oh[1 + ((50 * 2 - 1) * (50 * 2 - 1) + (50 * 2 - 1) + (50 * 2 - 1)) * 2];
int link(int o, int h) {
  static int _ = 1;
  oo[_] = o, oh[_] = h;
  return _++;
}
int ij[((50 * 2 - 1) * (50 * 2 - 1) + (50 * 2 - 1) + (50 * 2 - 1))],
    cc[((50 * 2 - 1) * (50 * 2 - 1) + (50 * 2 - 1) + (50 * 2 - 1)) * 2], m_;
int ae[((50 * 2 - 1) + (50 * 2 - 1) + 2)],
    dd[((50 * 2 - 1) + (50 * 2 - 1) + 2)], n_;
void link_(int i, int j, int c) {
  int h = m_++;
  ij[h] = i ^ j, cc[h << 1] = c;
  ae[i] = link(ae[i], h << 1);
  ae[j] = link(ae[j], h << 1 | 1);
}
int bfs(int s, int t) {
  static int qu[((50 * 2 - 1) + (50 * 2 - 1) + 2)];
  int i, head, cnt;
  for (i = 0; i < n_; i++) dd[i] = n_;
  head = cnt = 0;
  dd[s] = 0, qu[head + cnt++] = s;
  while (cnt) {
    int d, o;
    i = qu[cnt--, head++];
    d = dd[i] + 1;
    for (o = ae[i]; o; o = oo[o]) {
      int h_ = oh[o];
      if (cc[h_]) {
        int h = h_ >> 1, j = i ^ ij[h];
        if (dd[j] > d) {
          dd[j] = d;
          if (j == t) return 1;
          qu[head + cnt++] = j;
        }
      }
    }
  }
  return 0;
}
int dfs(int i, int t, int c) {
  int d, o;
  if (i == t) return c;
  d = dd[i] + 1;
  for (o = ae[i]; o; o = oo[o]) {
    int h_ = oh[o];
    if (cc[h_]) {
      int h = h_ >> 1, j = i ^ ij[h];
      if (dd[j] == d) {
        int f = dfs(j, t, min(c, cc[h_]));
        if (f) {
          cc[h_] -= f, cc[h_ ^ 1] += f;
          return f;
        }
      }
    }
  }
  dd[i] = n_;
  return 0;
}
int dinic(int s, int t) {
  int sum = 0, f;
  while (bfs(s, t))
    while ((f = dfs(s, t, 0x3f3f3f3f))) sum += f;
  return sum;
}
int main() {
  static int xx[50 * 2], yy[50 * 2], xx_[50 * 2], yy_[50 * 2], hh[50 * 2];
  static char used[(50 * 2 - 1)][(50 * 2 - 1)];
  int n, m, nx, ny, h, i, j, s, t;
  scanf("%d%d", &n, &m);
  if (m == 0) {
    printf("0\n");
    return 0;
  }
  for (h = 0; h < m; h++) {
    int l = h << 1, r = h << 1 | 1;
    scanf("%d%d%d%d", &xx[l], &yy[l], &xx[r], &yy[r]), xx[r]++, yy[r]++;
  }
  for (h = 0; h < m * 2; h++) hh[h] = h;
  nx = compress(xx, hh, xx_, m * 2) - 1;
  ny = compress(yy, hh, yy_, m * 2) - 1;
  n_ = nx + ny + 2;
  for (h = 0; h < m; h++) {
    int l = h << 1, r = h << 1 | 1;
    for (i = xx[l]; i < xx[r]; i++)
      for (j = yy[l]; j < yy[r]; j++) used[i][j] = 1;
  }
  s = nx + ny, t = s + 1;
  for (i = 0; i < nx; i++)
    for (j = 0; j < ny; j++)
      if (used[i][j]) link_(i, nx + j, 0x3f3f3f3f);
  for (i = 0; i < nx; i++) link_(s, i, xx_[i + 1] - xx_[i]);
  for (j = 0; j < ny; j++) link_(nx + j, t, yy_[j + 1] - yy_[j]);
  printf("%d\n", dinic(s, t));
  return 0;
}