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;
map<long long, long long> zipx;
long long unzipx[2000];
long long inf = 1LL << 50;
long long compressx(vector<long long>& x) {
  sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  for (long long i = 0; i < x.size(); i++) {
    zipx[x[i]] = i;
    unzipx[i] = x[i];
  }
  return x.size();
}
map<long long, long long> zipy;
long long unzipy[2000];
long long compressy(vector<long long>& x) {
  sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  for (long long i = 0; i < x.size(); i++) {
    zipy[x[i]] = i;
    unzipy[i] = x[i];
  }
  return x.size();
}
template <typename T>
class Dinic {
 private:
  struct edge {
    long long to;
    T cap;
    long long rev;
  };
  long long V;
  vector<vector<edge> > G;
  vector<long long> level, iter;
  void bfs(long long s) {
    fill(level.begin(), level.end(), -1);
    queue<long long> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
      long long v = que.front();
      que.pop();
      for (auto& e : G[v]) {
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }
  T dfs(long long v, long long t, T f) {
    if (v == t) {
      return f;
    }
    for (long long& i = iter[v]; i < (long long)G[v].size(); i++) {
      edge& e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        T d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

 public:
  Dinic(long long node_size) : V(node_size), G(V), level(V), iter(V) {}
  void add_edge(long long from, long long to, T cap) {
    G[from].push_back((edge){to, cap, (long long)G[to].size()});
    G[to].push_back((edge){from, (T)0, (long long)G[from].size() - 1});
  }
  T solve(long long s, long long t) {
    T flow = 0;
    for (;;) {
      bfs(s);
      if (level[t] < 0) return flow;
      fill(iter.begin(), iter.end(), 0);
      T f;
      while ((f = dfs(s, t, numeric_limits<T>::max())) > 0) {
        flow += f;
      }
    }
  }
};
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > a;
  vector<pair<long long, long long> > b;
  vector<long long> x;
  vector<long long> y;
  for (long long i = 0; i < (long long)(m); ++i) {
    long long p, q, r, s;
    cin >> p >> q >> r >> s;
    a.push_back(make_pair(p, q));
    b.push_back(make_pair(r + 1, s + 1));
    x.push_back(p);
    y.push_back(q);
    x.push_back(r + 1);
    y.push_back(s + 1);
  }
  long long s = compressx(x);
  long long t = compressy(y);
  vector<vector<bool> > f(s + 10, vector<bool>(t + 10));
  for (long long i = 0; i < (long long)(m); ++i) {
    for (long long j = zipx[a[i].first]; j < zipx[b[i].first]; j++) {
      for (long long k = zipy[a[i].second]; k < zipy[b[i].second]; k++) {
        f[j][k] = 1;
      }
    }
  }
  Dinic<long long> dn(s + t + 2);
  long long S = s + t;
  long long T = s + t + 1;
  for (long long i = 0; i < (long long)(s - 1); ++i) {
    dn.add_edge(S, i, unzipx[i + 1] - unzipx[i]);
  }
  for (long long j = 0; j < (long long)(t - 1); ++j) {
    dn.add_edge(s + j, T, unzipy[j + 1] - unzipy[j]);
  }
  for (long long i = 0; i < (long long)(s); ++i) {
    for (long long j = 0; j < (long long)(t); ++j) {
      if (f[i][j]) {
        dn.add_edge(i, s + j, inf);
      }
    }
  }
  cout << dn.solve(S, T) << endl;
  return 0;
}