Problem: There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs min(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost.

The square is large, so we give it to you in a compressed way. The set of black cells is the union of m rectangles.

Input

The first line contains two integers n and m (1 ≤ n ≤ 10^{9}, 0 ≤ m ≤ 50) — the size of the square grid and the number of black rectangles.

Each of the next m lines contains 4 integers x_{i1} y_{i1} x_{i2} y_{i2} (1 ≤ x_{i1} ≤ x_{i2} ≤ n, 1 ≤ y_{i1} ≤ y_{i2} ≤ n) — the coordinates of the bottom-left and the top-right corner cells of the i-th black rectangle.

The rectangles may intersect.

Output

Print a single integer — the minimum total cost of painting the whole square in white.

Examples

Input


10 2
4 1 5 10
1 4 10 5


Output


4


Input


7 6
2 1 2 1
4 2 4 3
2 5 2 5
2 3 5 3
1 2 1 2
3 2 5 3


Output


3

Note

The examples and some of optimal solutions are shown on the pictures below.

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const long long maxN = 2e5 + 5, mod = 1e9 + 7, inf = LLONG_MAX / 1000ll;
long long N, M;
struct ed {
  long long f, t, c, s;
  ed(long long f = 0, long long t = 0, long long c = 0)
      : f(f), t(t), c(c), s(0) {}
  bool full() { return s == c; }
};
struct dinic {
  long long F = 0;
  vector<ed> E;
  vector<long long> d, ptr;
  vector<long long> out[500 + 5];
  dinic() { d = ptr = vector<long long>(500 + 5, 0); }
  void add(long long f, long long t, long long c) {
    assert(f != t);
    out[f].push_back(E.size());
    E.push_back(ed(f, t, c));
    out[t].push_back(E.size());
    E.push_back(ed(t, f, 0));
  }
  long long send(long long u, long long sent) {
    if (u == 500) return sent;
    for (long long &p = ptr[u]; p < out[u].size(); ++p) {
      long long id = out[u][p];
      long long v = E[id].t;
      if (E[id].full() or d[v] <= d[u]) continue;
      long long t = send(v, min(sent, E[id].c - E[id].s));
      if (t) {
        E[id].s += t;
        E[id ^ 1].s -= t;
        assert(E[id].f == E[id ^ 1].t and E[id].t == E[id ^ 1].f);
        return t;
      }
    }
    return 0;
  }
  void bfs() {
    d[1] = 0;
    queue<long long> q;
    q.push(1);
    while (!q.empty()) {
      long long u = q.front();
      q.pop();
      for (long long id : out[u]) {
        long long v = E[id].t;
        if (E[id].full() or d[v] <= d[u] + 1) continue;
        d[v] = d[u] + 1;
        q.push(v);
      }
    }
  }
  long long run() {
    while (1) {
      fill(begin(d), end(d), inf);
      bfs();
      if (d[500] == inf) return F;
      fill(begin(ptr), end(ptr), 0);
      while (long long t = send(1, inf)) {
        F += t;
      }
    }
  }
} flow;
set<long long> xs, ys;
struct segment {
  long long l, r;
  segment(long long l = 0, long long r = 0) : l(l), r(r) {}
};
vector<segment> h, w;
bool in(segment &t, long long l, long long r) { return l <= t.l and t.r <= r; }
long long l1(long long x) { return x + 2; }
long long l2(long long y) { return y + h.size() + 2; }
bool check(segment &t, long long l, long long r) {
  if (in(t, l, r)) return 1;
  if (t.l > r) return 1;
  if (l > t.r) return 1;
  return 0;
}
void de(long long x1, long long y1, long long x2, long long y2) {
  for (long long i = (long long)0; i <= (long long)(long long)h.size() - 1;
       i++) {
    assert(check(h[i], x1, x2));
    if (in(h[i], x1, x2)) {
      for (long long j = (long long)0; j <= (long long)(long long)w.size() - 1;
           j++) {
        assert(check(w[j], y1, y2));
        if (in(w[j], y1, y2)) {
          flow.add(l1(i), l2(j), inf);
        }
      }
    }
  }
}
void bf() {
  for (long long i = (long long)0; i <= (long long)(long long)h.size() - 1;
       i++) {
    flow.add(1, l1(i), h[i].r - h[i].l + 1);
  }
  for (long long i = (long long)0; i <= (long long)(long long)w.size() - 1;
       i++) {
    flow.add(l2(i), 500, w[i].r - w[i].l + 1);
  }
}
void bseg() {
  xs.insert(0);
  xs.insert(N);
  ys.insert(0);
  ys.insert(N);
  for (auto it = xs.begin(); it != xs.end(); ++it) {
    if (next(it) != xs.end()) {
      h.push_back(segment((*it) + 1, *next(it)));
    }
  }
  for (auto it = ys.begin(); it != ys.end(); ++it) {
    if (next(it) != ys.end()) {
      w.push_back(segment((*it) + 1, *next(it)));
    }
  }
}
long long ul[maxN], ll[maxN], dl[maxN], rl[maxN];
signed main() {
  cin >> N >> M;
  for (long long i = (long long)1; i <= (long long)M; i++) {
    cin >> ul[i] >> ll[i] >> dl[i] >> rl[i];
    xs.insert(ul[i] - 1);
    xs.insert(dl[i]);
    ys.insert(ll[i] - 1);
    ys.insert(rl[i]);
  }
  bseg();
  bf();
  for (long long i = (long long)1; i <= (long long)M; i++) {
    de(ul[i], ll[i], dl[i], rl[i]);
  }
  long long ans = flow.run();
  cout << ans;
}