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>
#pragma GCC optimize("O3")
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1LL;
  long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = mul(_ret, _a, _mod);
  return _ret;
}
long long mymul(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 0LL;
  long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = add(_ret, _a, _mod);
  return _ret;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, _cs;
struct Maxflow {
  static const int MAXV = 100010;
  static const int INF = 1000000;
  struct Edge {
    int v, c, r;
    Edge(int _v, int _c, int _r) : v(_v), c(_c), r(_r) {}
  };
  int s, t;
  vector<Edge> G[MAXV * 2];
  int iter[MAXV * 2], d[MAXV * 2], gap[MAXV * 2], tot;
  void init(int x) {
    tot = x + 2;
    s = x + 1, t = x + 2;
    for (int i = 0; i <= tot; i++) {
      G[i].clear();
      iter[i] = d[i] = gap[i] = 0;
    }
  }
  void addEdge(int u, int v, int c) {
    G[u].push_back(Edge(v, c, (int)(G[v]).size()));
    G[v].push_back(Edge(u, 0, (int)(G[u]).size() - 1));
  }
  int dfs(int p, int flow) {
    if (p == t) return flow;
    int ret = 0;
    for (int &i = iter[p]; i < (int)(G[p]).size(); i++) {
      Edge &e = G[p][i];
      if (e.c > 0 && d[p] == d[e.v] + 1) {
        int f = dfs(e.v, min(flow, e.c));
        ret += f;
        flow -= f;
        e.c -= f;
        G[e.v][e.r].c += f;
        if (flow == 0) {
          break;
        }
      }
    }
    if (ret > 0) {
      return ret;
    }
    if ((--gap[d[p]]) == 0)
      d[s] = tot;
    else {
      d[p]++;
      iter[p] = 0;
      ++gap[d[p]];
    }
    return 0;
  }
  int solve() {
    int res = 0;
    gap[0] = tot;
    for (res = 0; d[s] < tot; res += dfs(s, INF))
      ;
    return res;
  }
} flow;
int tg[10101 << 2];
int mn[10101 << 2], mx[10101 << 2];
void push(int no, int l, int r) {
  if (!tg[no]) return;
  tg[(no << 1)] += tg[no];
  mn[(no << 1)] += tg[no];
  mx[(no << 1)] += tg[no];
  tg[(1 + (no << 1))] += tg[no];
  mn[(1 + (no << 1))] += tg[no];
  mx[(1 + (no << 1))] += tg[no];
  tg[no] = 0;
}
void modify(int no, int l, int r, int ql, int qr, int qd) {
  if (r < ql or l > qr) return;
  if (ql <= l and r <= qr) {
    tg[no] += qd;
    mn[no] += qd;
    mx[no] += qd;
    return;
  }
  push(no, l, r);
  modify((no << 1), l, ((l + r) >> 1), ql, qr, qd);
  modify((1 + (no << 1)), ((l + r) >> 1) + 1, r, ql, qr, qd);
  mn[no] = min(mn[(no << 1)], mn[(1 + (no << 1))]);
  mx[no] = max(mx[(no << 1)], mx[(1 + (no << 1))]);
}
int id[10101 << 2], stmp;
void mark(int no, int l, int r) {
  id[no] = ++stmp;
  if (l == r) return;
  mark((no << 1), l, ((l + r) >> 1));
  mark((1 + (no << 1)), ((l + r) >> 1) + 1, r);
}
void build_edge(int no, int l, int r) {
  if (l == r) {
    flow.addEdge(flow.s, id[no], 1);
    flow.addEdge(id[no] + stmp, flow.t, 1);
    return;
  }
  flow.addEdge(id[(no << 1)], id[no], 10101);
  flow.addEdge(id[(1 + (no << 1))], id[no], 10101);
  flow.addEdge(id[no] + stmp, id[(no << 1)] + stmp, 10101);
  flow.addEdge(id[no] + stmp, id[(1 + (no << 1))] + stmp, 10101);
  build_edge((no << 1), l, ((l + r) >> 1));
  build_edge((1 + (no << 1)), ((l + r) >> 1) + 1, r);
}
void build() {}
int n, m;
vector<pair<pair<int, int>, int> > dlt[10101];
vector<int> candx;
void init() {
  n = getint();
  mark(1, 1, n);
  flow.init(stmp + stmp);
  build_edge(1, 1, n);
  m = getint();
  while (m--) {
    int sdfjklsj = getint();
    int sdfjklsl = getint();
    int sdfjklsk = getint();
    int sdfjklsm = getint();
    dlt[sdfjklsj].push_back({{sdfjklsl, sdfjklsm}, +1});
    dlt[sdfjklsk + 1].push_back({{sdfjklsl, sdfjklsm}, -1});
    candx.push_back(sdfjklsj);
    candx.push_back(sdfjklsk + 1);
  }
}
vector<int> lid;
void find_id(int no, int l, int r, int ql, int qr) {
  if (r < ql or l > qr) return;
  if (ql <= l and r <= qr) {
    lid.push_back(id[no]);
    return;
  }
  find_id((no << 1), l, ((l + r) >> 1), ql, qr);
  find_id((1 + (no << 1)), ((l + r) >> 1) + 1, r, ql, qr);
}
void gogo(int no, int l, int r) {
  if (mn[no] > 0) return;
  if (mx[no] == 0) {
    for (auto ii : lid) flow.addEdge(ii, id[no] + stmp, 10101);
    return;
  }
  if (l == r) return;
  push(no, l, r);
  gogo((no << 1), l, ((l + r) >> 1));
  gogo((1 + (no << 1)), ((l + r) >> 1) + 1, r);
}
void solve() {
  if (candx.empty()) {
    printf("%d\n", n);
    exit(0);
  }
  sort(candx.begin(), candx.end());
  candx.resize(unique(candx.begin(), candx.end()) - candx.begin());
  if (candx[0] > 1) {
    lid.clear();
    find_id(1, 1, n, 1, candx[0] - 1);
    gogo(1, 1, n);
  }
  for (size_t _ = 0; _ < candx.size(); _++) {
    int x = candx[_];
    int til = _ + 1 < candx.size() ? candx[_ + 1] - 1 : n;
    for (auto i : dlt[x])
      modify(1, 1, n, i.first.first, i.first.second, i.second);
    lid.clear();
    find_id(1, 1, n, x, til);
    gogo(1, 1, n);
  }
  printf("%d\n", flow.solve());
}
int main() {
  build();
  while (__--) {
    init();
    solve();
  }
}