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;
using ll = long long;
const ll inf = LLONG_MAX >> 5;
const int N = 50005, M = 10000005;
namespace FlowGraph {
int head[N], v[M], nxt[M], ptr, tt;
ll w[M];
inline void padd_edge(int uu, int vv, ll ww) {
  v[ptr] = vv;
  w[ptr] = ww;
  nxt[ptr] = head[uu];
  head[uu] = ptr++;
}
int dis[N], cur[N];
bool vis[N];
bool bfs(int s, int t) {
  memset(vis, 0, sizeof(vis));
  memset(dis, -1, sizeof(dis));
  queue<int> q;
  q.push(s);
  dis[s] = 1;
  while (!q.empty()) {
    int nd = q.front();
    q.pop();
    for (int i = head[nd]; i != -1; i = nxt[i])
      if (w[i] && dis[v[i]] == -1) {
        dis[v[i]] = dis[nd] + 1;
        q.push(v[i]);
      }
  }
  return dis[t] != -1;
}
ll dfs(int pos, ll flow) {
  if (pos == tt) return flow;
  ll tmp = flow;
  for (int &i = cur[pos]; i != -1; i = nxt[i])
    if (w[i] && dis[v[i]] == dis[pos] + 1) {
      ll fl = dfs(v[i], min(flow, w[i]));
      w[i] -= fl;
      w[i ^ 1] += fl;
      flow -= fl;
      if (!flow) break;
    }
  return tmp - flow;
}
void init() {
  memset(head, -1, sizeof(head));
  memset(nxt, -1, sizeof(nxt));
}
inline void add_edge(int uu, int vv, ll ww) {
  padd_edge(uu, vv, ww);
  padd_edge(vv, uu, 0);
}
ll dinic(int s, int t) {
  tt = t;
  ll ret = 0;
  while (bfs(s, t)) memcpy(cur, head, sizeof(cur)), ret += dfs(s, inf);
  return ret;
}
};  // namespace FlowGraph
int sz, ss, tt;
inline int id(int l, int r, int tp) { return tp * sz + ((l + r) | (l != r)); }
void build(int l, int r, int tp) {
  int pos = id(l, r, tp);
  if (l == r) {
    if (!tp)
      FlowGraph::add_edge(ss, pos, 1);
    else
      FlowGraph::add_edge(pos, tt, 1);
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, tp);
  build(mid + 1, r, tp);
  if (!tp)
    FlowGraph::add_edge(id(l, mid, tp), pos, inf),
        FlowGraph::add_edge(id(mid + 1, r, tp), pos, inf);
  else
    FlowGraph::add_edge(pos, id(l, mid, tp), inf),
        FlowGraph::add_edge(pos, id(mid + 1, r, tp), inf);
}
using pii = pair<int, int>;
void modify(int l, int r, int tp, int ql, int qr, vector<pii> &s) {
  if (l == ql && r == qr) return s.push_back({id(l, r, tp), r - l + 1});
  int mid = (l + r) >> 1;
  if (qr <= mid)
    modify(l, mid, tp, ql, qr, s);
  else if (ql > mid)
    modify(mid + 1, r, tp, ql, qr, s);
  else
    modify(l, mid, tp, ql, mid, s), modify(mid + 1, r, tp, mid + 1, qr, s);
}
int n, q;
void update(int tl, int tr, int ql, int qr) {
  static vector<pii> a, b;
  a.clear();
  b.clear();
  modify(1, n, 0, tl, tr, a);
  modify(1, n, 1, ql, qr, b);
  for (auto &i : a)
    for (auto &j : b)
      FlowGraph::add_edge(i.first, j.first, i.second * j.second);
}
struct Node {
  int r1, r2, c;
  bool tp;
} mat[N];
int lf[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> q;
  int idx = 0;
  for (int i = 1, r1, r2, c1, c2; i <= q; i++)
    cin >> r1 >> c1 >> r2 >> c2, mat[++idx] = {r1, r2, c1, 0},
                                 mat[++idx] = {r1, r2, c2, 1};
  mat[++idx] = {1, n, n + 1, 0};
  mat[++idx] = {1, n, n + 1, 1};
  sort(mat + 1, mat + idx + 1,
       [](Node a, Node b) { return a.c == b.c ? a.tp < b.tp : a.c < b.c; });
  sz = id(n, n, 0);
  ss = sz * 2 + 3;
  tt = ss + 1;
  FlowGraph::init();
  build(1, n, 0);
  build(1, n, 1);
  for (int i = 1; i <= idx; i++) {
    if (mat[i].tp == 1)
      for (int j = mat[i].r1; j <= mat[i].r2; j++) lf[j] = mat[i].c;
    else
      for (int j = mat[i].r1, lw = mat[i].c - 1, lh = 0; j <= mat[i].r2 + 1;
           j++)
        if (j == mat[i].r2 + 1 || lf[j] != lw) {
          if (lw + 1 < mat[i].c) update(lh, j - 1, lw + 1, mat[i].c - 1);
          lw = lf[j];
          lh = j;
        }
  }
  cout << FlowGraph::dinic(ss, tt) << endl;
  return 0;
}