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 = 10010, inf = 1061109567;
struct Tree {
  int l, r;
} t[N << 2];
struct node {
  int to, flow, nxt;
} h[5000100];
int n, m, S, T, cnt, D, tot, head[500100], he[N], dep[500100];
bool mp[N][N];
vector<pair<int, int> > ve;
int read() {
  int aa = 0, bb = 1;
  char cc = getchar();
  while (cc > '9' || cc < '0') {
    if (cc == '-') bb = -1;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9') {
    aa = (aa << 3) + (aa << 1) + (cc ^ '0');
    cc = getchar();
  }
  return aa * bb;
}
void add(int x, int y, int flow) {
  h[++tot].to = y;
  h[tot].flow = flow;
  h[tot].nxt = head[x];
  head[x] = tot;
}
void link(int x, int y, int flow) {
  add(x, y, flow);
  add(y, x, 0);
}
void build(int x, int l, int r) {
  t[x].l = l;
  t[x].r = r;
  if (l == r) return cnt = max(cnt, x), void();
  int mid = l + r >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
}
void query(int x, int l, int r, int id, int opt) {
  if (l <= t[x].l && t[x].r <= r) {
    if (opt)
      link(id, x + D, t[x].r - t[x].l + 1);
    else
      link(x, id, t[x].r - t[x].l + 1);
    return;
  }
  int mid = t[x].l + t[x].r >> 1;
  if (l <= mid) query(x << 1, l, r, id, opt);
  if (r > mid) query(x << 1 | 1, l, r, id, opt);
}
void Link(int x, int opt) {
  if (t[x].l == t[x].r) {
    if (opt) link(x + D, T, 1);
    return;
  }
  Link(x << 1, opt);
  Link(x << 1 | 1, opt);
  int mid = t[x].l + t[x].r >> 1;
  if (opt)
    link(x + D, (x << 1) + D, mid - t[x].l + 1),
        link(x + D, (x << 1 | 1) + D, t[x].r - mid);
  else
    link(x, x << 1, mid - t[x].l + 1), link(x, x << 1 | 1, t[x].r - mid);
}
bool bfs() {
  queue<int> q;
  memset(dep, 0, sizeof(dep));
  dep[S] = 1;
  q.push(S);
  while (q.size()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i; i = h[i].nxt) {
      int y = h[i].to;
      if (h[i].flow > 0 && !dep[y]) dep[y] = dep[x] + 1, q.push(y);
    }
  }
  return dep[T];
}
int dfs(int x, int flow) {
  if (x == T || flow <= 0) return flow;
  int res = flow;
  for (int i = head[x]; i; i = h[i].nxt) {
    int y = h[i].to;
    if (h[i].flow <= 0 || dep[y] != dep[x] + 1) continue;
    int tmp = dfs(y, min(res, h[i].flow));
    if (!tmp) dep[y] = 0;
    h[i].flow -= tmp;
    h[i ^ 1].flow += tmp;
    res -= tmp;
    if (!res) break;
  }
  return flow - res;
}
int dinic() {
  int ans = 0;
  while (bfs()) ans += dfs(S, inf);
  return ans;
}
int main() {
  n = read();
  m = read();
  tot = 1;
  int x, y, xx, yy;
  for (int i = 1; i <= m; i++) {
    x = read();
    y = read();
    xx = read();
    yy = read();
    for (int j = x; j <= xx; j++)
      for (int k = y; k <= yy; k++) mp[j][k] = 1;
  }
  for (int i = 1; i <= n; i++) mp[n + 1][i] = 1;
  build(1, 1, n);
  D = cnt;
  cnt += cnt;
  S = ++cnt;
  T = ++cnt;
  Link(1, 0);
  Link(1, 1);
  link(S, 1, n);
  for (int i = 1; i <= n + 1; i++) {
    ve.clear();
    for (int j = 1; j <= n; j++) {
      if (!mp[i][j])
        he[j]++;
      else if (he[j])
        ve.push_back(make_pair(j, he[j])), he[j] = 0;
    }
    int p = 0;
    for (int j = 0; j < ve.size(); j++) {
      p = j;
      while (p + 1 < ve.size() && ve[p].first + 1 == ve[p + 1].first &&
             ve[p].second == ve[p + 1].second)
        p++;
      cnt++;
      query(1, ve[j].first, ve[p].first, cnt, 0);
      query(1, i - ve[j].second, i - 1, cnt, 1);
      j = p;
    }
  }
  printf("%d\n", dinic());
  return 0;
}