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;
int ID;
namespace MF {
int const N = 100000, M = 6000000, inf = 1e9;
int E, sr, sn, dis[N], vis[N + 1], vs;
vector<int> g[N];
pair<int, int> ed[M];
queue<int> st;
bool path() {
  ++vs;
  st.push(sr);
  vis[sr] = vs;
  dis[sr] = 0;
  dis[sn] = inf;
  while (!st.empty()) {
    int v = st.front();
    st.pop();
    if (dis[v] + 1 >= dis[sn]) continue;
    for (int &t : g[v]) {
      int u = ed[t].first, c = ed[t].second;
      if (c && vis[u] != vs) {
        vis[u] = vs;
        dis[u] = dis[v] + 1;
        st.push(u);
      }
    }
  }
  for (int i = 0; i < (int)(ID); ++i) random_shuffle(g[i].begin(), g[i].end());
  return vis[sn] == vs;
}
int go(int v = sr, int s = inf) {
  if (v == sn) return s;
  for (int &t : g[v]) {
    int u = ed[t].first, &c = ed[t].second, a;
    if (c && dis[u] == dis[v] + 1 && vis[u] == vs && (a = go(u, min(s, c)))) {
      c -= a;
      ed[t ^ 1].second += a;
      return a;
    }
  }
  dis[v] = inf;
  return 0;
}
inline int MF(int a, int b) {
  sr = a, sn = b;
  int an = 0, t;
  while (path())
    while (t = go()) an += t;
  return an;
}
inline void aded(int a, int b, int w1 = 1, int w2 = 0) {
  ed[E] = make_pair(b, w1);
  ed[E + 1] = make_pair(a, w2);
  g[a].push_back(E++);
  g[b].push_back(E++);
}
}  // namespace MF
int const N = 10000, inf = 1e9;
int n, idl[N << 2], idr[N << 2];
vector<pair<bool, pair<int, int> > > ev[N + 2];
void pl(int idv[], int l = 1, int r = n, int id = 1) {
  idv[id] = ID++;
  if (l == r) return;
  int m = l + r >> 1, a = id << 1, b = a | 1;
  pl(idv, l, m, a);
  pl(idv, m + 1, r, b);
}
vector<int> sg[2];
void flsg(int idv[], vector<int> &sg, int x, int y, int l = 1, int r = n,
          int id = 1) {
  if (y < l || x > r) return;
  if (l >= x && r <= y) {
    sg.push_back(idv[id]);
    return;
  }
  int m = l + r >> 1, a = id << 1, b = a | 1;
  flsg(idv, sg, x, y, l, m, a);
  flsg(idv, sg, x, y, m + 1, r, b);
}
inline void aded(int l1, int r1, int l2, int r2) {
  if (l1 > r1) return;
  for (int i = 0; i < (int)(2); ++i) sg[i].clear();
  flsg(idl, sg[0], l1, r1);
  flsg(idr, sg[1], l2, r2);
  int t = ID++;
  for (int i = 0; i < (int)(sg[0].size()); ++i) MF::aded(sg[0][i], t, inf);
  for (int i = 0; i < (int)(sg[1].size()); ++i) MF::aded(t, sg[1][i], inf);
}
struct S {
  int l;
  int mutable r, x;
  S(int a) : l(a) {}
  S(int a, int b, int c) : l(a), r(b), x(c) {}
  bool operator<(S const &o) const { return l < o.l; }
};
inline void ads(set<S> &st, int x, int l, int r) {
  auto it = --st.lower_bound(l);
  if (it->r >= l) {
    if (it->r <= r) {
      aded(it->x, x - 1, l, it->r);
      it->r = l - 1;
    } else {
      aded(it->x, x - 1, l, r);
      st.insert(S(r + 1, it->r, it->x));
      it->r = l - 1;
      return;
    }
  }
  ++it;
  while (true) {
    if (it->l > r) break;
    if (it->r <= r) {
      aded(it->x, x - 1, it->l, it->r);
      st.erase(it++);
    } else {
      aded(it->x, x - 1, it->l, r);
      st.insert(S(r + 1, it->r, it->x));
      st.erase(it);
      break;
    }
  }
}
void allsg(int idv[], vector<int> &sg, int i, int l = 1, int r = n,
           int id = 1) {
  sg.push_back(idv[id]);
  if (l == r) return;
  int m = l + r >> 1, a = id << 1, b = a | 1;
  if (i <= m)
    allsg(idv, sg, i, l, m, a);
  else
    allsg(idv, sg, i, m + 1, r, b);
}
int main() {
  int q;
  scanf("%d%d", &n, &q);
  pl(idl);
  pl(idr);
  set<S> st;
  st.insert(S(0, 0, 1));
  st.insert(S(1, n, 1));
  st.insert(S(n + 1, n + 1, 1));
  for (int i = 0; i < (int)(q); ++i) {
    int x[2], y[2];
    for (int i = 0; i < (int)(2); ++i) scanf("%d%d", x + i, y + i);
    pair<int, int> s(y[0], y[1]);
    ev[x[0]].push_back(make_pair(1, s));
    ev[x[1] + 1].push_back(make_pair(0, s));
  }
  ev[n + 1].push_back(make_pair(1, make_pair(1, n)));
  for (int i = 1; i < (int)(n + 2); ++i) {
    sort(ev[i].begin(), ev[i].end());
    for (auto &t : ev[i])
      if (t.first == 0)
        st.insert(S(t.second.first, t.second.second, i));
      else
        ads(st, i, t.second.first, t.second.second);
  }
  int sr = ID++, sn = ID++;
  for (int i = 1; i < (int)(n + 1); ++i) {
    sg[0].clear();
    allsg(idl, sg[0], i);
    int x = ID++;
    MF::aded(sr, x);
    for (int &v : sg[0]) MF::aded(x, v, inf);
  }
  for (int i = 1; i < (int)(n + 1); ++i) {
    sg[1].clear();
    allsg(idr, sg[1], i);
    int x = ID++;
    MF::aded(x, sn);
    for (int &v : sg[1]) MF::aded(v, x, inf);
  }
  printf("%d\n", MF::MF(sr, sn));
}