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>
const int MAXN = 10000;
const int MAXM = 100000;
const int MAXK = 2000000;
const int INF = 0x3f3f3f3f;
namespace Dinic {
struct Edge {
  int v, nxt, cap;
  Edge(int _v = 0, int _nxt = 0, int _cap = 0) {
    v = _v, nxt = _nxt, cap = _cap;
  }
} E[MAXK * 2 + 5];
int N, EdgeCnt, Adj[MAXM + 5], Cur[MAXM + 5];
void Init() {
  EdgeCnt = 0;
  memset(Adj, -1, sizeof Adj);
}
inline void AddEdge(int u, int v, int c) {
  E[EdgeCnt] = Edge(v, Adj[u], c), Adj[u] = EdgeCnt++;
  E[EdgeCnt] = Edge(u, Adj[v], 0), Adj[v] = EdgeCnt++;
}
void Print() {
  for (int i = 1; i <= N; i++) {
    printf("%d: ", i);
    for (int j = Adj[i]; ~j; j = E[j].nxt)
      printf("(%d, %d) ", E[j].v, E[j].cap);
    puts("");
  }
}
int Dist[MAXM + 5];
bool Bfs(int S, int T) {
  std::queue<int> Q;
  std::fill(Dist + 1, Dist + N + 1, -1);
  Dist[S] = 0, Q.push(S);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = Adj[u]; ~i; i = E[i].nxt) {
      int v = E[i].v, c = E[i].cap;
      if (c && Dist[v] == -1) {
        Dist[v] = Dist[u] + 1, Q.push(v);
        if (v == T) return true;
      }
    }
  }
  return false;
}
int Dfs(int u, int T, int flow) {
  if (u == T || !flow) return flow;
  int del = 0, go = 0;
  for (int i = Adj[u]; ~i; i = E[i].nxt) {
    int v = E[i].v, c = E[i].cap;
    if (Dist[v] != Dist[u] + 1) continue;
    if (del = Dfs(v, T, std::min(flow - go, c))) {
      go += del, E[i].cap -= del, E[i ^ 1].cap += del;
      if (go >= flow) break;
    }
  }
  if (!go) Dist[u] = -1;
  return go;
}
int MaxFlow(int S, int T) {
  int ret = 0;
  while (Bfs(S, T)) {
    for (int i = 1; i <= N; i++) Cur[i] = Adj[i];
    ret += Dfs(S, T, INF);
  }
  return ret;
}
}  // namespace Dinic
int N, Q, S, T;
int Left[MAXN + 5];
std::vector<int> C[2];
std::vector<std::pair<int, int> > Seg[MAXN + 5][2];
int ID[2][(MAXN << 2) + 5], IDCnt;
void GetID(int u, int l, int r, int i) {
  ID[i][u] = ++IDCnt;
  if (l == r) return;
  int mid = (l + r) >> 1;
  GetID((u << 1), l, mid, i);
  GetID((u << 1 | 1), mid + 1, r, i);
}
void Build(int u, int l, int r, int i) {
  if (l == r) {
    if (i)
      Dinic::AddEdge(ID[i][u], T, 1);
    else
      Dinic::AddEdge(S, ID[i][u], 1);
    return;
  }
  if (i) {
    Dinic::AddEdge(ID[i][u], ID[i][(u << 1)], INF);
    Dinic::AddEdge(ID[i][u], ID[i][(u << 1 | 1)], INF);
  } else {
    Dinic::AddEdge(ID[i][(u << 1)], ID[i][u], INF);
    Dinic::AddEdge(ID[i][(u << 1 | 1)], ID[i][u], INF);
  }
  int mid = (l + r) >> 1;
  Build((u << 1), l, mid, i);
  Build((u << 1 | 1), mid + 1, r, i);
}
void Cover(int u, int l, int r, int lft, int rgt, int i) {
  if (lft <= l && r <= rgt) {
    C[i].push_back(ID[i][u]);
    return;
  }
  int mid = (l + r) >> 1;
  if (lft <= mid) Cover((u << 1), l, mid, lft, rgt, i);
  if (mid + 1 <= rgt) Cover((u << 1 | 1), mid + 1, r, lft, rgt, i);
}
void Insert(int j1, int i1, int j2, int i2) {
  if (i1 > i2 || j1 > j2) return;
  C[0].clear(), C[1].clear();
  Cover(1, 1, N, i1, i2, 0);
  Cover(1, 1, N, j1, j2, 1);
  for (int i = 0; i < int(C[0].size()); i++)
    for (int j = 0; j < int(C[1].size()); j++)
      Dinic::AddEdge(C[0][i], C[1][j], INF);
}
int main() {
  scanf("%d%d", &N, &Q);
  IDCnt = 1;
  GetID(1, 1, N, 0), GetID(1, 1, N, 1);
  Dinic::Init(), S = 1, Dinic::N = T = IDCnt + 1;
  Build(1, 1, N, 0), Build(1, 1, N, 1);
  for (int i = 1; i <= Q; i++) {
    int i1, j1, i2, j2;
    scanf("%d%d%d%d", &i1, &j1, &i2, &j2);
    Seg[j1][0].push_back(std::make_pair(i1, i2));
    Seg[j2][1].push_back(std::make_pair(i1, i2));
  }
  Seg[N + 1][0].push_back(std::make_pair(1, N));
  for (int i = 1; i <= N + 1; i++) {
    for (int j = 0; j < int(Seg[i][0].size()); j++) {
      int up = Seg[i][0][j].first, dwn = Seg[i][0][j].second;
      for (int k = up + 1; k <= dwn; k++)
        if (Left[k] != Left[k - 1])
          Insert(up, Left[k - 1] + 1, k - 1, i - 1), up = k;
      Insert(up, Left[dwn] + 1, dwn, i - 1);
    }
    for (int j = 0; j < int(Seg[i][1].size()); j++)
      for (int k = Seg[i][1][j].first; k <= Seg[i][1][j].second; k++)
        Left[k] = i;
  }
  printf("%d", Dinic::MaxFlow(S, T));
  return 0;
}