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;
int n, m, tot = 0, h[1000127], cnt = 1, SS, TT;
struct Edge {
  int to, next, s;
} e[1000127 << 2];
inline void AddEdge(int x, int y, int s) {
  e[++cnt] = (Edge){y, h[x], s};
  h[x] = cnt;
  e[++cnt] = (Edge){x, h[y], 0};
  h[y] = cnt;
}
int dep[1000127];
queue<int> q;
bool bfs(int S, int T) {
  int i, x, y;
  for (i = 1; i <= tot; i++) dep[i] = 0x3f3f3f3f;
  q.push(S);
  dep[S] = 0;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    for (i = h[x]; i; i = e[i].next)
      if (e[i].s && (dep[y = e[i].to] == 0x3f3f3f3f)) {
        dep[y] = dep[x] + 1;
        q.push(y);
      }
  }
  return (dep[T] < 0x3f3f3f3f);
}
int dfs(int x, int flow, int T) {
  if (x == T) return flow;
  int i, y, res = 0, dlt;
  for (i = h[x]; i && flow; i = e[i].next)
    if (e[i].s && (dep[y = e[i].to] == dep[x] + 1)) {
      dlt = dfs(y, min(e[i].s, flow), T);
      if (!dlt) {
        dep[y] = 0x3f3f3f3f;
        continue;
      }
      e[i].s -= dlt;
      e[i ^ 1].s += dlt;
      res += dlt;
      flow -= dlt;
    }
  return res;
}
int dinic(int S, int T) {
  int maxflow = 0, d = 0;
  while (bfs(S, T))
    while (d = dfs(S, 0x3f3f3f3f, T)) maxflow += d;
  return maxflow;
}
int a[1000127], b[1000127], A[1000127], B[1000127];
void builda(int p, int l, int r) {
  A[p] = ++tot;
  if (l == r) {
    AddEdge(a[l], A[p], 0x3f3f3f3f);
    return;
  }
  int mid = (l + r) >> 1;
  builda(p << 1, l, mid);
  builda(p << 1 | 1, mid + 1, r);
  AddEdge(A[p << 1], A[p], 0x3f3f3f3f);
  AddEdge(A[p << 1 | 1], A[p], 0x3f3f3f3f);
}
void buildb(int p, int l, int r) {
  B[p] = ++tot;
  if (l == r) {
    AddEdge(B[p], b[r], 0x3f3f3f3f);
    return;
  }
  int mid = (l + r) >> 1;
  buildb(p << 1, l, mid);
  buildb(p << 1 | 1, mid + 1, r);
  AddEdge(B[p], B[p << 1], 0x3f3f3f3f);
  AddEdge(B[p], B[p << 1 | 1], 0x3f3f3f3f);
}
void Adda(int p, int l, int r, int L, int R, int v) {
  if ((R < l) || (r < L)) return;
  if ((L <= l) && (r <= R)) {
    AddEdge(A[p], v, 0x3f3f3f3f);
    return;
  }
  int mid = (l + r) >> 1;
  Adda(p << 1, l, mid, L, R, v);
  Adda(p << 1 | 1, mid + 1, r, L, R, v);
}
void Addb(int p, int l, int r, int L, int R, int v) {
  if ((R < l) || (r < L)) return;
  if ((L <= l) && (r <= R)) {
    AddEdge(v, B[p], 0x3f3f3f3f);
    return;
  }
  int mid = (l + r) >> 1;
  Addb(p << 1, l, mid, L, R, v);
  Addb(p << 1 | 1, mid + 1, r, L, R, v);
}
struct Rec {
  int l1, r1, l2, r2;
};
vector<Rec> S;
struct sec {
  int l, r, v;
  inline bool operator<(const sec &y) const { return (r < y.r); }
};
set<sec> s;
set<sec>::iterator it;
vector<sec> tmp;
inline void Del(int l, int r, int v) {
  tmp.clear();
  int l1, r1;
  sec p;
  while (!s.empty()) {
    it = s.lower_bound((sec){0, l, 0});
    if ((it == s.end()) || ((it->l) > r)) break;
    p = *it;
    l1 = max(p.l, l);
    r1 = min(p.r, r);
    if ((p.v) < v) S.push_back((Rec){l1, r1, p.v, v - 1});
    s.erase(it);
    if (p.l < l) tmp.push_back((sec){p.l, l - 1, p.v});
    if (r < p.r) tmp.push_back((sec){r + 1, p.r, p.v});
  }
  while (!tmp.empty()) {
    s.insert(tmp.back());
    tmp.pop_back();
  }
}
inline void Ins(int l, int r, int v) {
  int l1 = l, r1 = r;
  sec p;
  while (!s.empty()) {
    it = s.lower_bound((sec){0, l, 0});
    if ((it == s.end()) || ((it->l) > r)) break;
    p = *it;
    l1 = min(l1, p.l);
    r1 = max(r1, p.r);
    if ((p.v) < v) S.push_back((Rec){p.l, p.r, p.v, v - 1});
    s.erase(it);
  }
  s.insert((sec){l1, r1, v});
}
vector<sec> I[10127], D[10127];
int main() {
  scanf("%d%d", &n, &m);
  int i, l1, r1, l2, r2;
  SS = ++tot;
  TT = ++tot;
  for (i = 1; i <= n; i++) a[i] = ++tot, AddEdge(SS, a[i], 1);
  builda(1, 1, n);
  for (i = 1; i <= n; i++) b[i] = ++tot, AddEdge(b[i], TT, 1);
  buildb(1, 1, n);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &l1, &l2, &r1, &r2);
    D[l2].push_back((sec){l1, r1, l2});
    I[r2 + 1].push_back((sec){l1, r1, r2 + 1});
  }
  s.insert((sec){1, n, 1});
  for (i = 1; i <= n; i++) {
    for (auto v : I[i]) Ins(v.l, v.r, v.v);
    for (auto v : D[i]) Del(v.l, v.r, v.v);
  }
  Del(1, n, n + 1);
  for (auto v : S) {
    ++tot;
    Adda(1, 1, n, v.l1, v.r1, tot);
    Addb(1, 1, n, v.l2, v.r2, tot);
  }
  printf("%d", dinic(SS, TT));
  return 0;
}