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;
const int INF = 0x7fffffff;
const int NIL = -1;
template <class T>
inline T mx(T a, T b) {
  return a > b ? a : b;
}
template <class T>
inline T mi(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline void sw(T &a, T &b) {
  T t = a;
  a = b;
  b = t;
}
template <class T>
inline T mabs(T x) {
  return x < 0 ? -x : x;
}
inline char gc() {
  char ret;
  while ((ret = getchar()) == ' ' || ret == '\n' || ret == '\t')
    ;
  return ret;
}
template <class T>
inline T sq(T x) {
  return x * x;
}
const int LIM = 60;
const int SZ = 1e6;
struct Q {
  int sx, tx, sy, ty;
} ques[LIM];
int adj[SZ], idcur = 1;
struct Edge {
  int v, w, nxt;
} edges[SZ];
int ecur = -1;
inline void _add(int u, int v, int w) {
  edges[++ecur].v = v;
  edges[ecur].w = w;
  edges[ecur].nxt = adj[u];
  adj[u] = ecur;
}
inline void add(int u, int v, int w) {
  _add(u, v, w);
  _add(v, u, 0);
}
inline void init() { memset((adj), (-1), sizeof(adj)); }
inline void buildNode(set<int> &seg, map<pair<int, int>, int> &mp, int rt) {
  set<int>::iterator ite = seg.begin();
  while (ite != seg.end()) {
    int spos = *(ite++);
    if (ite == seg.end()) break;
    int tpos = *ite;
    int idx = mp[make_pair(spos, tpos - 1)] = ++idcur;
    if (!rt)
      add(rt, idx, tpos - spos);
    else
      add(idx, rt, tpos - spos);
  }
}
int tadj[SZ], lev[SZ];
inline bool bfs() {
  for (int i = 0; i <= idcur; i++) {
    lev[i] = -1;
    tadj[i] = adj[i];
  }
  static int que[SZ];
  int h = 0, t = 0;
  que[t++] = 0;
  lev[0] = 0;
  while (h < t) {
    int crt = que[h++];
    for (int i = adj[crt]; i != -1; i = edges[i].nxt) {
      int v = edges[i].v;
      if (lev[v] == -1 && edges[i].w > 0) {
        lev[v] = lev[crt] + 1;
        que[t++] = v;
      }
    }
  }
  return lev[1] != -1;
}
inline int dfs(int u, int buflow) {
  if (!buflow || u == 1) return buflow;
  int ret = 0, cap = buflow;
  for (int &i = tadj[u]; i != -1; i = edges[i].nxt) {
    int v = edges[i].v, &w = edges[i].w, f;
    if (w > 0 && lev[v] == lev[u] + 1 && (f = dfs(v, mi(cap, w)))) {
      cap -= f, ret += f, w -= f, edges[i ^ 1].w += f;
      if (!cap) return ret;
    }
  }
  return ret;
}
inline int dinic() {
  int ret = 0;
  while (bfs()) ret += dfs(0, INF);
  return ret;
}
int main(void) {
  init();
  int n, m;
  scanf("%d%d", &n, &m);
  set<int> xseg, yseg;
  xseg.insert(1), xseg.insert(n + 1), yseg.insert(1), yseg.insert(n + 1);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d%d", &ques[i].sx, &ques[i].sy, &ques[i].tx, &ques[i].ty);
    xseg.insert(ques[i].sx), xseg.insert(ques[i].tx + 1);
    yseg.insert(ques[i].sy), yseg.insert(ques[i].ty + 1);
  }
  map<pair<int, int>, int> xmp, ymp;
  buildNode(xseg, xmp, 0), buildNode(yseg, ymp, 1);
  for (auto tmp : xmp) {
    for (int i = 0; i < m; i++) {
      if (ques[i].sx <= tmp.first.first && ques[i].tx >= tmp.first.second) {
        map<pair<int, int>, int>::iterator ite =
            ymp.lower_bound(make_pair(ques[i].sy, ques[i].sy));
        while (ite != ymp.end() && ite->first.second <= ques[i].ty) {
          add(tmp.second, ite->second, INF);
          ++ite;
        }
      }
    }
  }
  printf("%d\n", dinic());
  return 0;
}