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;
void Get_Val(int &Ret) {
  Ret = 0;
  char ch;
  while (ch = getchar(), ch > '9' || ch < '0')
    ;
  do {
    (Ret *= 10) += ch - '0';
  } while (ch = getchar(), ch >= '0' && ch <= '9');
}
const int Max_N(20050);
const int INF(0X3F3F3F3F);
namespace G {
const int Max_V(200000);
const int Max_E(5000000);
int V, S, T;
int Head[Max_V], Total, To[Max_E], Next[Max_E], Cap[Max_E], Flow[Max_E];
inline void Add_Edge(const int &tot, const int &s, const int &t, const int &c) {
  To[tot] = t, Next[tot] = Head[s], Head[s] = tot, Cap[tot] = c, Flow[tot] = 0;
}
inline void Add_Link(const int &s, const int &t, const int &c) {
  Total += 2, Add_Edge(Total, s, t, c), Add_Edge(Total ^ 1, t, s, 0);
}
int Cur[Max_V], Dist[Max_V];
bool BFS() {
  queue<int> Q;
  memset(Dist, 0, sizeof(Dist)), Q.push(S), Dist[S] = 1;
  int u, v;
  while (Q.size()) {
    u = Q.front(), Q.pop();
    for (int i = Head[u]; i; i = Next[i])
      if (Cap[i] > Flow[i] && !Dist[v = To[i]])
        Dist[v] = Dist[u] + 1, Q.push(v);
  }
  return Dist[T];
}
int DFS(const int &u, int a) {
  if (u == T || a == 0) return a;
  int Ans(0), f;
  for (int &i = Cur[u], v; i; i = Next[i])
    if (Dist[v = To[i]] == Dist[u] + 1 &&
        (f = DFS(v, min(a, Cap[i] - Flow[i]))) > 0) {
      Flow[i] += f, Flow[i ^ 1] -= f, Ans += f;
      if ((a -= f) == 0) break;
    }
  return Ans;
}
int Dinic() {
  int Ans(0);
  while (BFS()) {
    for (int i = 1; i <= V; ++i) Cur[i] = Head[i];
    Ans += DFS(S, INF);
  }
  return Ans;
}
}  // namespace G
struct node {
  int lch, rch;
};
int tot, rootX, rootY;
node segt[Max_N << 2];
struct Segment_Tree {
  void build_tree(int &, const int &, const int &, const bool &);
  void link(const int &, const int &, const int &, const int &, const int &,
            const int &, const bool &);
  void link(const int &, const int &, const int &, const bool &);
};
Segment_Tree X, Y;
void Segment_Tree::build_tree(int &cur, const int &LEFT, const int &RIGHT,
                              const bool &which) {
  if (!cur) segt[++tot] = segt[cur], cur = tot;
  if (LEFT == RIGHT) return;
  int MID = LEFT + ((RIGHT - LEFT) >> 1);
  build_tree((segt[cur].lch), LEFT, MID, which),
      build_tree((segt[cur].rch), MID + 1, RIGHT, which);
  if (which)
    G::Add_Link((segt[cur].lch), cur, INF),
        G::Add_Link((segt[cur].rch), cur, INF);
  else
    G::Add_Link(cur, (segt[cur].lch), INF),
        G::Add_Link(cur, (segt[cur].rch), INF);
}
void Segment_Tree::link(const int &cur, const int &LEFT, const int &RIGHT,
                        const int &l, const int &r, const int &v,
                        const bool &which) {
  if (LEFT == l && RIGHT == r) {
    if (which)
      G::Add_Link(cur, v, INF);
    else
      G::Add_Link(v, cur, INF);
    return;
  }
  int MID = LEFT + ((RIGHT - LEFT) >> 1);
  if (r <= MID)
    link((segt[cur].lch), LEFT, MID, l, r, v, which);
  else if (l > MID)
    link((segt[cur].rch), MID + 1, RIGHT, l, r, v, which);
  else {
    link((segt[cur].lch), LEFT, MID, l, MID, v, which);
    link((segt[cur].rch), MID + 1, RIGHT, MID + 1, r, v, which);
  }
}
void Segment_Tree::link(const int &cur, const int &LEFT, const int &RIGHT,
                        const bool &which) {
  if (LEFT == RIGHT) {
    if (which)
      G::Add_Link(G::S, cur, 1);
    else
      G::Add_Link(cur, G::T, 1);
    return;
  }
  int MID = LEFT + ((RIGHT - LEFT) >> 1);
  link((segt[cur].lch), LEFT, MID, which),
      link((segt[cur].rch), MID + 1, RIGHT, which);
}
struct seg {
  seg(const int &_l = 0, const int &_r = 0, const int &_v = 0)
      : l(_l), r(_r), v(_v) {}
  int l, r, v;
};
inline bool operator<(const seg &a, const seg &b) { return a.l < b.l; }
set<seg> S;
vector<seg> V[Max_N];
inline bool comp(const seg &a, const seg &b) { return a.v < b.v; }
int N, M;
int main() {
  Get_Val(N), Get_Val(M);
  X.build_tree(rootX, 1, N, true), Y.build_tree(rootY, 1, N, false);
  G::V = tot + 2, G::S = tot + 1, G::T = tot + 2;
  X.link(rootX, 1, N, true), Y.link(rootY, 1, N, false);
  for (int i = 1, x1, y1, x2, y2; i <= M; ++i) {
    Get_Val(x1), Get_Val(y1), Get_Val(x2), Get_Val(y2);
    V[x1].push_back(seg(y1, y2, +1)), V[x2 + 1].push_back(seg(y1, y2, -1));
  }
  set<seg>::iterator it;
  S.insert(seg(1, N, 1));
  for (int x = 1, l, r, v, nowl, nowr, ll, rr; x <= N; ++x) {
    sort(V[x].begin(), V[x].end(), comp);
    for (int i = 0; i != V[x].size(); ++i) {
      l = V[x][i].l, r = V[x][i].r;
      if (V[x][i].v == -1)
        S.insert(seg(l, r, x));
      else
        while (S.size()) {
          it = S.upper_bound(seg(r, 0, 0)), --it;
          if ((nowl = max(l, ll = it->l)), (nowr = min(r, rr = it->r)),
              (nowl <= nowr)) {
            v = it->v;
            if (v <= x - 1) {
              ++G::V;
              X.link(rootX, 1, N, v, x - 1, G::V, true);
              Y.link(rootY, 1, N, nowl, nowr, G::V, false);
            }
            S.erase(it);
            if (ll <= nowl - 1) S.insert(seg(ll, nowl - 1, v));
            if (nowr + 1 <= rr) S.insert(seg(nowr + 1, rr, v));
          } else
            break;
        }
    }
  }
  while (S.size()) {
    it = S.begin();
    ++G::V;
    X.link(rootX, 1, N, it->v, N, G::V, true);
    Y.link(rootY, 1, N, it->l, it->r, G::V, false);
    S.erase(it);
  }
  printf("%d", G::Dinic());
  return 0;
}