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 inf = 1e9;
const int N = 10010;
const int M = 400100;
int h[M], level[M], q[M];
int n, m, tot = 1, ans, vs, vt;
int from[N];
int root1, root2, size;
int ls[N << 3], rs[N << 3];
struct edge {
  int y, next, z;
} g[N * 300];
struct node {
  int x, l, r, f;
  node(int _x = 0, int _l = 0, int _r = 0, int _f = 0)
      : x(_x), l(_l), r(_r), f(_f) {}
  friend bool operator<(node a, node b) {
    if (a.x == b.x) return a.f > b.f;
    return a.x < b.x;
  }
} a[N * 2];
void adp(int x, int y, int z) {
  g[++tot].y = y;
  g[tot].z = z;
  g[tot].next = h[x];
  h[x] = tot;
  g[++tot].y = x;
  g[tot].z = 0;
  g[tot].next = h[y];
  h[y] = tot;
}
void build(int &rt, int pre, int l, int r, int kind) {
  rt = ++size;
  if (pre) {
    if (kind == 1)
      adp(rt, pre, inf);
    else
      adp(pre, rt, inf);
  }
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(ls[rt], rt, l, mid, kind);
  build(rs[rt], rt, mid + 1, r, kind);
}
void build2(int rt, int pre, int l, int r, int kind) {
  if (l == r) {
    if (kind == 2)
      adp(rt, pre, 1);
    else
      adp(pre, rt, 1);
    return;
  }
  int mid = (l + r) >> 1;
  build2(ls[rt], pre, l, mid, kind);
  build2(rs[rt], pre, mid + 1, r, kind);
}
void gao(int rt, int l, int r, int ll, int rr, int x, int kind) {
  if (!rt) return;
  if (ll <= l && r <= rr) {
    if (kind == 1)
      adp(rt, x, inf);
    else
      adp(x, rt, inf);
    return;
  }
  int mid = (l + r) >> 1;
  if (ll <= mid) gao(ls[rt], l, mid, ll, rr, x, kind);
  if (rr > mid) gao(rs[rt], mid + 1, r, ll, rr, x, kind);
}
void insert(int x, int l, int r) {
  int pos = -1, last = -1, y;
  for (int i = l; i <= r + 1; i++) {
    if (i <= r) y = from[i] + 1, from[i] = -1;
    if (y != last || i == r + 1) {
      if (pos != -1) {
        int tmp = ++size;
        gao(root1, 1, n, pos, i - 1, tmp, 1);
        gao(root2, 1, n, last, x, tmp, 2);
      }
      pos = i;
      last = y;
    }
  }
}
void change(int x, int l, int r) {
  for (int i = l; i <= r; i++) from[i] = x;
}
int bfs() {
  memset(level, 0, sizeof(level));
  int l = 0, r = 1;
  level[vs] = 1;
  q[1] = vs;
  while (l < r) {
    int x = q[++l];
    for (int i = h[x]; i; i = g[i].next)
      if (!level[g[i].y] && g[i].z) {
        level[g[i].y] = level[x] + 1;
        q[++r] = g[i].y;
        if (g[i].y == vt) return 1;
      }
  }
  return 0;
}
int dfs(int x, int flow) {
  if (x == vt || !flow) return flow;
  int res = 0;
  for (int i = h[x]; i; i = g[i].next)
    if (level[x] + 1 == level[g[i].y]) {
      int gt = dfs(g[i].y, min(flow, g[i].z));
      if (gt) {
        res += gt;
        flow -= gt;
        g[i].z -= gt;
        g[i ^ 1].z += gt;
      }
      if (!flow) break;
    }
  if (!res) level[x] = -1;
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  build(root1, 0, 1, n, 1);
  build(root2, 0, 1, n, 2);
  for (int i = 1; i <= m; i++) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    a[2 * i - 1] = node(x1 - 1, y1, y2, 0);
    a[2 * i] = node(x2, y1, y2, 1);
  }
  sort(a + 1, a + 2 * m + 1);
  for (int i = 1; i <= 2 * m; i++)
    if (!a[i].f)
      insert(a[i].x, a[i].l, a[i].r);
    else
      change(a[i].x, a[i].l, a[i].r);
  insert(n, 1, n);
  vs = 0;
  vt = ++size;
  build2(root1, vs, 1, n, 1);
  build2(root2, vt, 1, n, 2);
  while (bfs()) ans += dfs(vs, inf);
  printf("%d\n", ans);
}