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;
template <typename T>
void read(T &x) {
  x = 0;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    ;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
}
const int N = 255, P = 998244353, oo = 0x3f3f3f3f;
int mul(int a, int b) { return 1ll * a * b % P; }
int add(int a, int b) {
  a += b;
  return a >= P ? a - P : a;
}
int sub(int a, int b) {
  a -= b;
  return a < 0 ? a + P : a;
}
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
namespace Dinic {
const int S = N * N;
struct Edge {
  int d, cap, nxt;
} es[S << 2];
int vn, g[S], lev[S], itr[S], q[S], h, t, en = 1;
void add(int s, int d, int cap) {
  es[++en] = (Edge){d, cap, g[s]}, g[s] = en;
  es[++en] = (Edge){s, 0, g[d]}, g[d] = en;
}
void bfs(int s) {
  int v;
  memset(lev, -1, sizeof(lev));
  h = t = 0;
  q[t++] = s;
  lev[s] = 0;
  while (h < t) {
    v = q[h++];
    for (int i = g[v], d = es[i].d; i; i = es[i].nxt, d = es[i].d) {
      if (es[i].cap > 0 && lev[d] < 0) {
        lev[d] = lev[v] + 1;
        q[t++] = es[i].d;
      }
    }
  }
}
int dfs(int v, int t, int f) {
  if (v == t) return f;
  for (int &i = itr[v]; i; i = es[i].nxt) {
    if (es[i].cap <= 0 || lev[es[i].d] <= lev[v]) continue;
    int a = dfs(es[i].d, t, min(es[i].cap, f));
    if (a <= 0) continue;
    es[i].cap -= a;
    es[i ^ 1].cap += a;
    return a;
  }
  return 0;
}
int sol(int s, int t) {
  int i, res = 0, a;
  while (true) {
    bfs(s);
    if (lev[t] < 0) break;
    for (i = 0; i <= vn; ++i) itr[i] = g[i];
    for (a = dfs(s, t, oo); a > 0; a = dfs(s, t, oo)) {
      res += a;
    }
  }
  return res;
}
}  // namespace Dinic
using namespace Dinic;
int n, m;
vector<int> xx, yy;
struct Rec {
  int x1, y1, x2, y2;
} rec[N];
int f(vector<int> &a, int x) {
  return lower_bound(a.begin(), a.end(), x) - a.begin() + 1;
}
int main(int argc, char *argv[]) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= (m); ++i) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    --x1, --y1;
    xx.push_back(x1), xx.push_back(x2);
    yy.push_back(y1), yy.push_back(y2);
    rec[i] = (Rec){x1, y1, x2, y2};
  }
  xx.push_back(0), yy.push_back(0);
  sort(xx.begin(), xx.end()), sort(yy.begin(), yy.end());
  xx.erase(unique(xx.begin(), xx.end()), xx.end());
  yy.erase(unique(yy.begin(), yy.end()), yy.end());
  int sx = xx.size(), sxy = sx + yy.size(), src = sxy + m + 1, snk = src + 1;
  vn = snk;
  for (int i = 1; i < (xx.size()); ++i) {
    add(src, i + 1, xx[i] - xx[i - 1]);
  }
  for (int i = 1; i < (yy.size()); ++i) {
    add(sx + i + 1, snk, yy[i] - yy[i - 1]);
  }
  for (int i = 1; i <= (m); ++i) {
    int x1 = rec[i].x1, x2 = rec[i].x2, y1 = rec[i].y1, y2 = rec[i].y2;
    x1 = f(xx, x1);
    x2 = f(xx, x2);
    y1 = f(yy, y1);
    y2 = f(yy, y2);
    for (int j = x1 + 1; j <= x2; ++j) add(j, sxy + i, oo);
    for (int j = y1 + 1; j <= y2; ++j) add(sxy + i, sx + j, oo);
  }
  cout << sol(src, snk) << endl;
}