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;
void in(int &r) {
  static char c;
  r = 0;
  bool flag(0);
  while (c = getchar(), c < 48) (c == '-') && (flag = 1);
  do r = (r << 1) + (r << 3) + (c ^ 48);
  while (c = getchar(), c > 47);
  flag && (r = -r);
}
const int mn = 205;
const int mm = 21005;
int head[mn], ne[mm], to[mm], cnt1 = 1;
long long wi[mm];
int n, s, t, depth[mn], que[mn];
bool bfs() {
  fill(depth + 1, depth + n + 1, -1);
  int l = 0, r = 0;
  que[++r] = s;
  depth[s] = 1;
  while (l < r) {
    int now = que[++l];
    for (int q(head[now]); q; q = ne[q])
      if (wi[q] && depth[to[q]] == -1) {
        depth[to[q]] = depth[now] + 1;
        if (to[q] == t) return 1;
        que[++r] = to[q];
      }
  }
  return 0;
}
int cur[mn];
long long dfs(int x, long long flow) {
  if (x == t) return flow;
  long long used = 0;
  for (int &q = cur[x]; q; q = ne[q])
    if (wi[q] && depth[to[q]] == depth[x] + 1) {
      int fl = dfs(to[q], min(wi[q], flow - used));
      used += fl, wi[q] -= fl, wi[q ^ 1] += fl;
      if (used == flow) return used;
    }
  return used;
}
long long dinic() {
  long long ans = 0;
  while (bfs()) {
    for (int q = 1, q_end_ = n; q <= q_end_; ++q) cur[q] = head[q];
    ans += dfs(s, 1e18);
  }
  return ans;
}
struct node {
  int x, y, x1, y1;
} an[51];
int mid_x[105], mid_y[105];
bool had[105][105];
int main() {
  int n1, m1;
  in(n1), in(m1);
  int cnt_x = 0, cnt_y = 0;
  for (int q = 1, q_end_ = m1; q <= q_end_; ++q) {
    in(an[q].x), in(an[q].y), in(an[q].x1), in(an[q].y1), ++an[q].x1,
        ++an[q].y1;
    mid_x[++cnt_x] = an[q].x, mid_x[++cnt_x] = an[q].x1,
    mid_y[++cnt_y] = an[q].y, mid_y[++cnt_y] = an[q].y1;
  }
  sort(mid_x + 1, mid_x + cnt_x + 1);
  cnt_x = unique(mid_x + 1, mid_x + cnt_x + 1) - mid_x - 1;
  sort(mid_y + 1, mid_y + cnt_y + 1);
  cnt_y = unique(mid_y + 1, mid_y + cnt_y + 1) - mid_y - 1;
  for (int q = 1, q_end_ = m1; q <= q_end_; ++q) {
    an[q].x = lower_bound(mid_x + 1, mid_x + cnt_x + 1, an[q].x) - mid_x;
    an[q].x1 = lower_bound(mid_x + 1, mid_x + cnt_x + 1, an[q].x1) - mid_x;
    an[q].y = lower_bound(mid_y + 1, mid_y + cnt_y + 1, an[q].y) - mid_y;
    an[q].y1 = lower_bound(mid_y + 1, mid_y + cnt_y + 1, an[q].y1) - mid_y;
    for (int w = an[q].x + 1, w_end_ = an[q].x1; w <= w_end_; ++w)
      for (int e = an[q].y + 1, e_end_ = an[q].y1; e <= e_end_; ++e)
        if (!had[w][e])
          had[w][e] = 1, to[++cnt1] = cnt_x + e, ne[cnt1] = head[w],
          head[w] = cnt1, wi[cnt1] = 1e18, to[++cnt1] = w,
          ne[cnt1] = head[cnt_x + e], head[cnt_x + e] = cnt1, wi[cnt1] = 0;
  }
  s = cnt_x + cnt_y + 1, t = s + 1, n = t;
  for (int q = 2, q_end_ = cnt_x; q <= q_end_; ++q)
    to[++cnt1] = q, ne[cnt1] = head[s], head[s] = cnt1,
    wi[cnt1] = mid_x[q] - mid_x[q - 1], to[++cnt1] = s, ne[cnt1] = head[q],
    head[q] = cnt1, wi[cnt1] = 0;
  for (int q = 2, q_end_ = cnt_y; q <= q_end_; ++q)
    to[++cnt1] = t, ne[cnt1] = head[q + cnt_x], head[q + cnt_x] = cnt1,
    wi[cnt1] = mid_y[q] - mid_y[q - 1], to[++cnt1] = q + cnt_x,
    ne[cnt1] = head[t], head[t] = cnt1, wi[cnt1] = 0;
  printf("%lld\n", dinic());
  return 0;
}