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 = 1e4 + 7;
int n, q, tot = 1, cnt, s, t;
bool mp[N][N];
int h[N], id[N << 2][2];
int dep[N << 3], head[N << 3], to[N << 8], w[N << 8], nxt[N << 8];
inline void link(int a, int b, int c) {
  nxt[++tot] = head[a];
  to[head[a] = tot] = b;
  w[tot] = c;
  nxt[++tot] = head[b];
  to[head[b] = tot] = a;
  w[tot] = 0;
}
void build(int p, int l, int r) {
  id[p][0] = ++cnt;
  id[p][1] = ++cnt;
  if (l == r) return link(s, id[p][0], 1), link(id[p][1], t, 1);
  const int mid = l + r >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  link(id[p << 1][0], id[p][0], N);
  link(id[p << 1 | 1][0], id[p][0], N);
  link(id[p][1], id[p << 1][1], N);
  link(id[p][1], id[p << 1 | 1][1], N);
}
void insert(int p, int opt, int Id, int l, int r, int L, int R) {
  if (L >= l && R <= r)
    return opt ? link(Id, id[p][opt], N) : link(id[p][opt], Id, N);
  const int mid = L + R >> 1;
  if (l <= mid) insert(p << 1, opt, Id, l, r, L, mid);
  if (r > mid) insert(p << 1 | 1, opt, Id, l, r, mid + 1, R);
}
int dinic(int x, int flow) {
  if (x == t) return flow;
  int res = flow, k;
  for (int i = head[x]; i && res; i = nxt[i])
    if (w[i] && dep[to[i]] == dep[x] + 1) {
      k = dinic(to[i], min(res, w[i]));
      res -= k;
      w[i] -= k;
      w[i ^ 1] += k;
      if (!k) dep[to[i]] = 0;
    }
  return flow - res;
}
inline bool bfs() {
  memset(dep, 0, sizeof(dep));
  queue<int> q;
  q.push(s);
  dep[s] = 1;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i; i = nxt[i])
      if (w[i] && !dep[to[i]]) {
        dep[to[i]] = dep[x] + 1;
        q.push(to[i]);
        if (to[i] == t) return 1;
      }
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &q);
  s = ++cnt;
  t = ++cnt;
  for (int i = 1, x, y, X, Y; i <= q; ++i) {
    scanf("%d%d%d%d", &x, &y, &X, &Y);
    for (int j = x; j <= X; ++j)
      for (int k = y; k <= Y; ++k) mp[j][k] = 1;
  }
  for (int i = 1; i <= n; ++i) mp[n + 1][i] = 1;
  build(1, 1, n);
  for (int i = 1; i <= n + 1; ++i) {
    vector<pair<int, int> > ve;
    for (int j = 1; j <= n; ++j) {
      if (!mp[i][j])
        ++h[j];
      else {
        if (h[j]) ve.push_back(make_pair(j, h[j]));
        h[j] = 0;
      }
    }
    for (int l = 0, r = 1; l < ve.size(); l = r++) {
      while (r < ve.size() && ve[r].first == ve[r - 1].first + 1 &&
             ve[r].second == ve[r - 1].second)
        ++r;
      int tl = ve[l].first, tr = ve[r - 1].first, L = i - ve[l].second,
          R = i - 1;
      ++cnt;
      insert(1, 0, cnt, tl, tr, 1, n);
      insert(1, 1, cnt, L, R, 1, n);
    }
  }
  int ans = 0;
  while (bfs()) ans += dinic(s, N);
  return printf("%d\n", ans), 0;
}