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;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
namespace network_flow {
const int max0 = 3000000, max1 = 10000000;
struct edge {
  int id, g, nxt;
  edge() {}
  edge(int _id, int _g, int _nxt) : id(_id), g(_g), nxt(_nxt) {}
};
int st[max0 + 5], en = 0;
edge e[max1 + 5];
inline void add_edge(int first, int second, int z) {
  e[en] = edge(second, z, st[first]), st[first] = en++;
}
inline void add_biedge(int first, int second, int z) {
  add_edge(first, second, z), add_edge(second, first, 0);
}
int S, T, N;
int dis[max0 + 5];
inline bool bfs() {
  static int q[max0 + 5];
  static bool vis[max0 + 5];
  int head = 0, rear = 0;
  memset(dis, -1, sizeof(dis[0]) * N);
  memset(vis, 0, sizeof(vis[0]) * N);
  vis[q[rear++] = S] = 1;
  dis[S] = 0;
  while (head != rear) {
    int first = q[head++];
    for (int i = st[first]; i != -1; i = e[i].nxt) {
      if (!e[i].g) continue;
      int second = e[i].id;
      if (!vis[second]) {
        dis[second] = dis[first] + 1;
        if (second == T) return 1;
        q[rear++] = second;
        vis[second] = 1;
      }
    }
  }
  return 0;
}
int cur[max0 + 5];
inline int dfs(int first, int flow) {
  if (first == T) return flow;
  int res = flow;
  for (int &i = cur[first]; i != -1; i = e[i].nxt) {
    if (!e[i].g) continue;
    int second = e[i].id;
    if (dis[second] == dis[first] + 1) {
      int F = dfs(second, min(e[i].g, res));
      res -= F;
      e[i].g -= F;
      e[i ^ 1].g += F;
      if (res <= 0) return flow;
    }
  }
  dis[first] = -1;
  return flow - res;
}
inline int work() {
  if (S == T) return oo;
  int ret = 0;
  for (; bfs();) {
    for (int i = (0), i_end_ = (N); i < i_end_; ++i) cur[i] = st[i];
    ret += dfs(S, oo);
  }
  return ret;
}
}  // namespace network_flow
using network_flow::add_biedge;
using network_flow::add_edge;
using network_flow::en;
using network_flow::N;
using network_flow::S;
using network_flow::st;
using network_flow::T;
using network_flow::work;
const int maxn = 10100;
int n, qn;
struct node;
node *newnode();
node *copy(node *first);
struct node {
  int id;
  int link;
  node *c[2];
  bool has, con;
  node() : has(0), con(0) { memset(c, 0, sizeof c); }
  void update() {
    has = con;
    for (int i = (0), i_end_ = (2); i < i_end_; ++i)
      if (c[i] && c[i]->has) has = 1;
  }
  void flag_label() {
    if (!con) add_biedge(id, link, oo);
    has = con = 1;
  }
};
const int max0 = 100000;
node *nd_pool;
int nd_res = 0;
inline node *newnode() {
  if (!nd_res) nd_pool = new node[max0], nd_res = max0;
  node *ret = nd_pool + (--nd_res);
  ret->id = N++;
  return ret;
}
inline node *copy(node *first) {
  node *tmp = newnode();
  int tmpid = tmp->id;
  *tmp = *first;
  tmp->id = tmpid;
  return tmp;
}
void build(node *&rt, int l, int r) {
  if (!rt) {
    rt = newnode();
    rt->link = N++;
  }
  if (r - l <= 1) {
    add_biedge(rt->link, T, 1);
    return;
  }
  int mid = (l + r) >> 1;
  build(rt->c[0], l, mid);
  build(rt->c[1], mid, r);
  for (int i = (0), i_end_ = (2); i < i_end_; ++i)
    add_biedge(rt->link, rt->c[i]->link, oo);
}
int seg_x, seg_y, seg_ty;
void clear(node *&rt) {
  if (!rt->has) return;
  rt = copy(rt);
  if (rt->con) rt->con = 0;
  rt->update();
  if (rt->has)
    for (int i = (0), i_end_ = (2); i < i_end_; ++i)
      if (rt->c[i]) clear(rt->c[i]);
  rt->update();
  for (int i = (0), i_end_ = (2); i < i_end_; ++i)
    if (rt->c[i]) add_biedge(rt->id, rt->c[i]->id, oo);
}
void add(node *&rt, int l, int r) {
  if (seg_x <= l && r <= seg_y) {
    if (!seg_ty) {
      clear(rt);
    } else
      rt = copy(rt), rt->flag_label();
    return;
  }
  rt = copy(rt);
  int mid = (l + r) >> 1;
  if (rt->con) {
    for (int i = (0), i_end_ = (2); i < i_end_; ++i)
      if (rt->c[i]) {
        rt->c[i] = copy(rt->c[i]);
        rt->c[i]->flag_label();
      }
    rt->con = 0;
  }
  if (seg_x < mid) add(rt->c[0], l, mid);
  if (seg_y > mid) add(rt->c[1], mid, r);
  rt->update();
  for (int i = (0), i_end_ = (2); i < i_end_; ++i)
    if (rt->c[i]) add_biedge(rt->id, rt->c[i]->id, oo);
}
vector<pair<int, pair<int, int> > > all[maxn + 5];
node *rt;
int main() {
  memset(st, -1, sizeof st);
  S = N++, T = N++;
  scanf("%d", &n);
  scanf("%d", &qn);
  build(rt, 0, n);
  rt->flag_label();
  for (int i = (0), i_end_ = (qn); i < i_end_; ++i) {
    int ux, uy, vx, vy;
    scanf("%d%d%d%d", &ux, &uy, &vx, &vy), --ux, --uy;
    all[ux].push_back(make_pair(0, make_pair(uy, vy)));
    all[vx].push_back(make_pair(1, make_pair(uy, vy)));
  }
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
    sort((all[i]).begin(), (all[i]).end());
    reverse((all[i]).begin(), (all[i]).end());
    for (auto u : all[i]) {
      seg_x = u.second.first, seg_y = u.second.second, seg_ty = u.first;
      add(rt, 0, n);
    }
    add_biedge(S, rt->id, 1);
  }
  printf("%d\n", work());
  return 0;
}