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 N = 10005;
const int Nd = 300005;
struct edge {
  int to, next, f;
} e[Nd * 5];
int head[Nd], tot = 1;
int S, T, sz;
void add(int x, int y, int v) {
  e[++tot] = (edge){y, head[x], v};
  head[x] = tot;
  e[++tot] = (edge){x, head[y], 0};
  head[y] = tot;
}
int dis[Nd], q[Nd];
bool bfs() {
  for (int i = (int)(1); i <= (int)(sz); i++) dis[i] = -1;
  int h = 0, t = 1;
  dis[q[1] = S] = 0;
  while (h != t) {
    int x = q[++h];
    for (int i = head[x]; i; i = e[i].next)
      if (dis[e[i].to] == -1 && e[i].f) {
        dis[e[i].to] = dis[x] + 1;
        if (e[i].to == T) return 1;
        q[++t] = e[i].to;
      }
  }
  return 0;
}
int dfs(int x, int flow) {
  if (x == T) return flow;
  int k, rest = flow;
  for (int i = head[x]; i && rest; i = e[i].next)
    if (dis[e[i].to] == dis[x] + 1 && e[i].f) {
      k = dfs(e[i].to, min(rest, e[i].f));
      e[i].f -= k;
      e[i ^ 1].f += k;
      rest -= k;
    }
  if (rest) dis[x] = -1;
  return flow - rest;
}
int lg[N], f[15][N], g[15][N];
void connect(int l, int r, int x, int y) {
  if (l > r || x > y) return;
  int k1 = lg[r - l + 1], k2 = lg[y - x + 1];
  add(f[k1][l], g[k2][x], (1 << 29));
  add(f[k1][l], g[k2][y - (1 << k2) + 1], (1 << 29));
  add(f[k1][r - (1 << k1) + 1], g[k2][x], (1 << 29));
  add(f[k1][r - (1 << k1) + 1], g[k2][y - (1 << k2) + 1], (1 << 29));
}
struct range {
  int x, l, r;
  bool operator<(const range &a) const {
    if (r != a.r) return r < a.r;
    if (l != a.l) return l > a.l;
    return x < a.x;
  }
};
set<range> s;
struct que {
  int tp, x, l, r;
} qq[N * 2];
void ins(que x) {
  set<range>::iterator it;
  it = s.end();
  it--;
  it = s.lower_bound((range){-1, x.l, x.r});
  int L = it->l, R = it->r;
  connect(it->x, x.x - 1, L, R);
  s.erase(it);
  if (L != x.l) s.insert((range){x.x, L, x.l - 1});
  if (R != x.r) s.insert((range){x.x, x.r + 1, R});
}
void del(que x) {
  set<range>::iterator it;
  it = s.lower_bound((range){-1, x.l, x.r});
  int R = x.r, L = x.l;
  if (it != s.end() && it->l == x.r + 1) {
    connect(it->x, x.x - 1, it->l, it->r);
    R = it->r;
    s.erase(it);
  }
  it = s.lower_bound((range){-1, x.l, x.r});
  if (it != s.begin())
    if ((--it)->r == x.l - 1) {
      connect(it->x, x.x - 1, it->l, it->r);
      L = it->l;
      s.erase(it);
    }
  s.insert((range){x.x, L, R});
}
bool cmp(que a, que b) {
  if (a.x != b.x) return a.x < b.x;
  return a.tp > b.tp;
}
int n, Q;
int main() {
  scanf("%d%d", &n, &Q);
  for (int i = (int)(2); i <= (int)(n); i++) lg[i] = lg[i / 2] + 1;
  sz = n * 2;
  S = ++sz;
  T = ++sz;
  for (int i = (int)(1); i <= (int)(n); i++) f[0][i] = i;
  for (int i = (int)(1); i <= (int)(14); i++)
    for (int j = (int)(1); j <= (int)(n - (1 << i) + 1); j++) {
      f[i][j] = ++sz;
      add(f[i - 1][j], f[i][j], (1 << 29));
      add(f[i - 1][j + (1 << (i - 1))], f[i][j], (1 << 29));
    }
  for (int i = (int)(1); i <= (int)(n); i++) g[0][i] = i + n;
  for (int i = (int)(1); i <= (int)(14); i++)
    for (int j = (int)(1); j <= (int)(n - (1 << i) + 1); j++) {
      g[i][j] = ++sz;
      add(g[i][j], g[i - 1][j], (1 << 29));
      add(g[i][j], g[i - 1][j + (1 << (i - 1))], (1 << 29));
    }
  for (int i = (int)(1); i <= (int)(n); i++) add(S, i, 1), add(i + n, T, 1);
  int cnt = 0;
  for (int i = (int)(1); i <= (int)(Q); i++) {
    int x, y, X, Y;
    scanf("%d%d%d%d", &x, &y, &X, &Y);
    qq[++cnt] = (que){1, x, y, Y};
    qq[++cnt] = (que){2, X + 1, y, Y};
  }
  s.insert((range){1, 1, n});
  sort(qq + 1, qq + cnt + 1, cmp);
  for (int i = (int)(1); i <= (int)(cnt); i++)
    if (qq[i].tp == 1)
      ins(qq[i]);
    else
      del(qq[i]);
  for (; s.begin() != s.end();) {
    range tmp = *s.begin();
    s.erase(s.begin());
    connect(tmp.x, n, tmp.l, tmp.r);
  }
  int ans = 0;
  for (; bfs(); ans += dfs(S, (1 << 29)))
    ;
  printf("%d\n", ans);
}