Problem: Oleg the bank client solves an interesting chess problem: place on n × n chessboard the maximum number of rooks so that they don't beat each other. Of course, no two rooks can share the same cell.

Remind that a rook standing in the cell (a, b) beats a rook standing in the cell (x, y) if and only if a = x or b = y.

Unfortunately (of fortunately?) for Oleg the answer in this problem was always n, so the task bored Oleg soon. He decided to make it more difficult by removing some cells from the board. If a cell is deleted, Oleg can't put a rook there, but rooks do beat each other "through" deleted cells.

Oleg deletes the cells in groups, namely, he repeatedly choose a rectangle with sides parallel to the board sides and deletes all the cells inside the rectangle. Formally, if he chooses a rectangle, lower left cell of which has coordinates (x1, y1), and upper right cell of which has coordinates (x2, y2), then he deletes all such cells with coordinates (x, y) that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2. It is guaranteed that no cell is deleted twice, i.e. the chosen rectangles do not intersect.

This version of the problem Oleg can't solve, and his friend Igor is busy at a conference, so he can't help Oleg.

You are the last hope for Oleg! Help him: given the size of the board and the deleted rectangles find the maximum possible number of rooks that could be placed on the board so that no two rooks beat each other.

Input

The first line contains single integer n (1 ≤ n ≤ 10000) — the size of the board.

The second line contains single integer q (0 ≤ q ≤ 10000) — the number of deleted rectangles.

The next q lines contain the information about the deleted rectangles.

Each of these lines contains four integers x1, y1, x2 and y2 (1 ≤ x1 ≤ x2 ≤ n, 1 ≤ y1 ≤ y2 ≤ n) — the coordinates of the lower left and the upper right cells of a deleted rectangle.

If is guaranteed that the rectangles do not intersect.

Output

In the only line print the maximum number of rooks Oleg can place on the board so that no two rooks beat each other.

Examples

Input

5
5
1 1 2 1
1 3 1 5
4 1 5 5
2 5 2 5
3 2 3 5


Output

3


Input

8
4
2 2 4 6
1 8 1 8
7 1 8 2
5 4 6 8


Output

8

Note

Here is the board and the example of rooks placement in the first example:

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxm = 1e5 + 10;
const int inf = 0x3f3f3f3f;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
template <typename A>
inline bool read(A &x) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-')
      f = -1;
    else if (c == EOF)
      return 0;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  x *= f;
  return 1;
}
inline bool read(char &x) {
  while ((x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                           (iS == iT ? EOF : *iS++))
                        : *iS++)) == ' ' ||
         x == '\n' || x == '\r')
    ;
  return x != EOF;
}
inline bool read(char *x) {
  while ((*x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                            (iS == iT ? EOF : *iS++))
                         : *iS++)) == '\n' ||
         *x == ' ' || *x == '\r')
    ;
  if (*x == EOF) return 0;
  while (!(*x == '\n' || *x == ' ' || *x == '\r' || *x == EOF))
    *(++x) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                          (iS == iT ? EOF : *iS++))
                       : *iS++);
  *x = 0;
  return 1;
}
template <typename A, typename... B>
inline bool read(A &x, B &...y) {
  return read(x) && read(y...);
}
template <typename A>
inline bool write(A x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
  return 0;
}
inline bool write(char x) {
  putc(x);
  return 0;
}
inline bool write(const char *x) {
  while (*x) {
    putc(*x);
    ++x;
  }
  return 0;
}
inline bool write(char *x) {
  while (*x) {
    putc(*x);
    ++x;
  }
  return 0;
}
template <typename A, typename... B>
inline bool write(A x, B... y) {
  return write(x) || write(y...);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::putc;
using io ::read;
using io ::write;
struct available {
  int x1, y1, x2, y2;
} rec[maxm];
struct DEL {
  int x1, x2, y, flag;
  friend bool operator<(DEL a, DEL b) { return a.y < b.y; }
} del[maxm];
int L[maxm];
struct node {
  int ls, rs;
} tree[maxm];
int n;
int cnt, ecnt;
struct Edge {
  int v, w, nxt;
} ed[maxm * 30];
vector<int> v1, v2;
int s, t, maxflow;
int head[maxm], cur[maxm], dep[maxm], pre[maxm], num[maxm];
void addedge(int u, int v, int w) {
  ed[ecnt] = {v, w, head[u]};
  head[u] = ecnt++;
  ed[ecnt] = {u, 0, head[v]};
  head[v] = ecnt++;
}
void bfs() {
  queue<int> q;
  for (int i = s; i <= t; i++) cur[i] = head[i];
  for (int i = s; i <= t; i++) dep[i] = t + 1;
  dep[t] = 0;
  q.push(t);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i != -1; i = ed[i].nxt)
      if (dep[ed[i].v] == t + 1 && ed[i ^ 1].w) {
        dep[ed[i].v] = dep[u] + 1;
        q.push(ed[i].v);
      }
  }
}
int add_flow() {
  int ans = inf, u = t;
  while (u != s) {
    ans = min(ans, ed[pre[u]].w);
    u = ed[pre[u] ^ 1].v;
  }
  u = t;
  while (u != s) {
    ed[pre[u]].w -= ans;
    ed[pre[u] ^ 1].w += ans;
    u = ed[pre[u] ^ 1].v;
  }
  return ans;
}
void isap() {
  int u = s;
  bfs();
  for (int i = s; i <= t; i++) num[dep[i]]++;
  while (dep[s] < t + 1) {
    if (u == t) maxflow += add_flow(), u = s;
    bool flag = 0;
    for (int &i = cur[u]; i != -1; i = ed[i].nxt)
      if (dep[u] == dep[ed[i].v] + 1 && ed[i].w) {
        flag = 1;
        u = ed[i].v;
        pre[ed[i].v] = i;
        break;
      }
    if (!flag) {
      int minn = t;
      for (int i = head[u]; i != -1; i = ed[i].nxt)
        if (ed[i].w) minn = min(minn, dep[ed[i].v]);
      if ((--num[dep[u]]) == 0) break;
      num[dep[u] = minn + 1]++;
      cur[u] = head[u];
      if (u != s) u = ed[pre[u] ^ 1].v;
    }
  }
}
void buildout(int l, int r, int &rt) {
  if (l == r) {
    rt = n + l;
    return;
  }
  int mid = l + r >> 1;
  if (!rt) rt = ++cnt;
  buildout(l, mid, tree[rt].ls);
  buildout(mid + 1, r, tree[rt].rs);
  addedge(rt, tree[rt].ls, inf);
  addedge(rt, tree[rt].rs, inf);
}
void buildin(int l, int r, int &rt) {
  if (l == r) {
    rt = l;
    return;
  }
  int mid = l + r >> 1;
  if (!rt) rt = ++cnt;
  buildin(l, mid, tree[rt].ls);
  buildin(mid + 1, r, tree[rt].rs);
  addedge(tree[rt].ls, rt, inf);
  addedge(tree[rt].rs, rt, inf);
}
void getinterval(int L, int R, int l, int r, int rt, vector<int> &v) {
  if (L <= l && r <= R) {
    v.push_back(rt);
    return;
  }
  int mid = l + r >> 1;
  if (L <= mid) getinterval(L, R, l, mid, tree[rt].ls, v);
  if (R > mid) getinterval(L, R, mid + 1, r, tree[rt].rs, v);
}
int main() {
  memset(head, -1, sizeof(head));
  int Q;
  read(n, Q);
  int cal = 0;
  for (int i = 1; i <= Q; i++) {
    int x1, y1, x2, y2;
    read(x1, y1, x2, y2);
    del[++cal] = {x1, x2, y1, 1};
    del[++cal] = {x1, x2, y2 + 1, 0};
  }
  sort(del + 1, del + cal + 1);
  for (int i = 1; i <= n; i++) L[i] = 1;
  L[0] = L[n + 1] = inf;
  del[++cal] = {1, n, n + 1, 1};
  int cal1 = 0;
  for (int i = 1; i <= cal; i++) {
    if (del[i].flag) {
      int x1 = del[i].x1, x2 = del[i].x2;
      int last = x1;
      for (int j = x1 + 1; j <= x2; j++) {
        if (L[j] != L[last]) {
          if (L[last] < del[i].y) {
            rec[++cal1] = {last, L[last], j - 1, del[i].y - 1};
          }
          last = j;
        }
      }
      if (L[last] < del[i].y) {
        rec[++cal1] = {last, L[last], x2, del[i].y - 1};
      }
      for (int j = x1; j <= x2; j++) L[j] = inf;
    } else {
      int x1 = del[i].x1, x2 = del[i].x2;
      for (int j = x1; j <= x2; j++) L[j] = del[i].y;
    }
  }
  int rt1 = 0, rt2 = 0;
  cnt = 2 * n;
  buildin(1, n, rt2);
  buildout(1, n, rt1);
  for (int i = 1; i <= cal1; i++) {
    int x1 = rec[i].x1, x2 = rec[i].x2, y1 = rec[i].y1, y2 = rec[i].y2;
    v1.clear();
    v2.clear();
    getinterval(x1, x2, 1, n, rt2, v1);
    getinterval(y1, y2, 1, n, rt1, v2);
    for (int j : v1) {
      for (int k : v2) {
        addedge(j, k, inf);
      }
    }
  }
  s = 0, t = cnt + 1;
  for (int i = 1; i <= n; i++) {
    addedge(s, i, 1);
    addedge(i + n, t, 1);
  }
  isap();
  printf("%d\n", maxflow);
  return 0;
}