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;
const double eps = 1e-9;
const long long oo = 0x3f3f3f3f3f3f3f3fLL;
const int MAXN = 2048 * 2048;
int DINIC_N, DINIC_SRC, DINIC_DST;
vector<int> adj[MAXN];
unordered_map<int, long long> residual[MAXN];
void reset(int n, int s, int t) {
  assert(n <= MAXN);
  DINIC_N = n, DINIC_SRC = s, DINIC_DST = t;
  for (int i = (0); i < (DINIC_N); i++) adj[i].clear();
  for (int i = (0); i < (MAXN); i++) residual[i].clear();
}
void add_edge(int a, int b, long long c) {
  adj[a].push_back(b);
  adj[b].push_back(a);
  residual[a][b] += c;
}
long long dinic_rek(int n, vector<int>& edges_done, vector<int>& dist,
                    long long flow) {
  if (n == DINIC_SRC) return flow;
  while (edges_done[n] < int((adj[n]).size())) {
    long long from = adj[n][edges_done[n]++], cur_flow;
    if (dist[from] + 1 == dist[n] && residual[from][n] > 0) {
      if (0 < (cur_flow = dinic_rek(from, edges_done, dist,
                                    min(flow, residual[from][n])))) {
        if (residual[from][n] -= cur_flow) --edges_done[n];
        residual[n][from] += cur_flow;
        return cur_flow;
      }
    }
  }
  return 0;
}
long long dinic() {
  for (int i = (0); i < (DINIC_N); i++) {
    sort((adj[i]).begin(), (adj[i]).end());
    auto it = unique((adj[i]).begin(), (adj[i]).end());
    adj[i].resize(distance(adj[i].begin(), it));
  }
  long long flow = 0, cur_flow = 0;
  while (true) {
    vector<int> dist(DINIC_N, DINIC_N), edges_done(DINIC_N, 0);
    queue<int> q;
    q.push(DINIC_SRC);
    dist[DINIC_SRC] = 0;
    while (!q.empty()) {
      int n = q.front();
      q.pop();
      if (n == DINIC_DST) break;
      for (auto to : adj[n]) {
        if (residual[n][to] > 0 && dist[to] == DINIC_N) {
          dist[to] = dist[n] + 1;
          q.push(to);
        }
      }
    }
    if (dist[DINIC_DST] == DINIC_N) return flow;
    while (0 < (cur_flow = dinic_rek(DINIC_DST, edges_done, dist, oo))) {
      flow += cur_flow;
    }
  }
}
pair<pair<int, int>, pair<int, int> > rectangles[100100];
map<int, int> intervals;
unordered_map<int, int> done;
int segtree[2][100100];
int get_mid(int f, int t) { return f + (t - f) / 2; }
int left_child(int id) { return id * 2 + 1; }
void build_nodes(int ID, int id, int from, int to) {
  segtree[ID][id] = DINIC_N++;
  if (from + 1 == to) {
    if (ID == 0) {
      add_edge(0, segtree[ID][id], 1);
    } else {
      add_edge(segtree[ID][id], 1, 1);
    }
  } else {
    int ch = left_child(id);
    int m = get_mid(from, to);
    build_nodes(ID, ch, from, m);
    build_nodes(ID, ch + 1, m, to);
    if (ID == 0) {
      add_edge(segtree[ID][ch], segtree[ID][id], oo);
      add_edge(segtree[ID][ch + 1], segtree[ID][id], oo);
    } else {
      add_edge(segtree[ID][id], segtree[ID][ch], oo);
      add_edge(segtree[ID][id], segtree[ID][ch + 1], oo);
    }
  }
}
void add_seg(int ID, int id, int to_n, int from, int to, int f, int t) {
  f = max(f, from);
  t = min(t, to);
  if (f >= t) return;
  if (f == from && to == t) {
    if (ID == 0) {
      add_edge(segtree[ID][id], to_n, oo);
    } else {
      add_edge(to_n, segtree[ID][id], oo);
    }
    return;
  }
  int m = get_mid(from, to);
  int ch = left_child(id);
  add_seg(ID, ch, to_n, from, m, f, t);
  add_seg(ID, ch + 1, to_n, m, to, f, t);
}
void calc() {
  int S;
  cin >> S;
  int R;
  cin >> R;
  for (int i = (0); i < (R); i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    rectangles[i * 2] =
        make_pair(pair<int, int>(x1 - 1, 1), pair<int, int>(y1 - 1, y2));
    rectangles[i * 2 + 1] =
        make_pair(pair<int, int>(x2, -1), pair<int, int>(y1 - 1, y2));
  }
  sort(rectangles, rectangles + (2 * R));
  rectangles[2 * R] = make_pair(pair<int, int>(S, 1), pair<int, int>(0, S));
  reset(2, 0, 1);
  intervals.clear();
  memset(segtree, -1, sizeof(segtree));
  for (int i = (0); i < (2); i++) build_nodes(i, 0, 0, S);
  intervals[S] = 0;
  done[S] = 0;
  for (int r = (0); r < (2 * R + 1); r++) {
    auto it = intervals.lower_bound(rectangles[r].second.second);
    if (rectangles[r].first.second == 1) {
      assert(it->first >= rectangles[r].second.second);
      assert(it->second <= rectangles[r].second.first);
      int n = DINIC_N++;
      add_seg(0, 0, n, 0, S, it->second, it->first);
      add_seg(1, 0, n, 0, S, done[it->first], rectangles[r].first.first);
      int l = it->second;
      int h = it->first;
      intervals[h] = rectangles[r].second.second;
      done[h] = rectangles[r].first.first;
      intervals[rectangles[r].second.first] = l;
      done[rectangles[r].second.first] = rectangles[r].first.first;
    } else {
      assert(intervals.find(rectangles[r].second.first) != intervals.end());
      assert(intervals.lower_bound(rectangles[r].second.second) !=
             intervals.end());
      assert(intervals.lower_bound(rectangles[r].second.second)->second ==
             rectangles[r].second.second);
      int n = DINIC_N++;
      int h1 = rectangles[r].second.first;
      int l1 = intervals[h1];
      int d1 = done[h1];
      intervals.erase(h1);
      done.erase(h1);
      add_seg(0, 0, n, 0, S, l1, h1);
      add_seg(1, 0, n, 0, S, d1, rectangles[r].first.first);
      n = DINIC_N++;
      int h2 = intervals.lower_bound(rectangles[r].second.second)->first;
      int l2 = intervals[h2];
      assert(l2 == rectangles[r].second.second);
      int d2 = done[h2];
      intervals[h2] = l1;
      done[h2] = rectangles[r].first.first;
      add_seg(0, 0, n, 0, S, l2, h2);
      add_seg(1, 0, n, 0, S, d2, rectangles[r].first.first);
    }
  }
  cout << dinic() << endl;
}
int main() { calc(); }