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>
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
using namespace std;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
template <class T, class U>
inline void checkmin(T &x, U y) {
  if (y < x) x = y;
}
template <class T, class U>
inline void checkmax(T &x, U y) {
  if (y > x) x = y;
}
template <class T, class U>
inline bool ifmax(T &x, U y) {
  if (y > x) return x = y, true;
  return false;
}
template <class T, class U>
inline bool ifmin(T &x, U y) {
  if (y < x) return x = y, true;
  return false;
}
template <class T>
inline void sort(T &a) {
  sort(a.begin(), a.end());
}
template <class T>
inline void rsort(T &a) {
  sort(a.rbegin(), a.rend());
}
template <class T>
inline void reverse(T &a) {
  reverse(a.begin(), a.end());
}
template <class T, class U>
inline istream &operator>>(istream &str, pair<T, U> &p) {
  return str >> p.first >> p.second;
}
template <class T>
inline istream &operator>>(istream &str, vector<T> &a) {
  for (auto &i : a) str >> i;
  return str;
}
template <class T>
inline T sorted(T a) {
  sort(a);
  return a;
}
template <class F>
struct Dinic {
  struct Edge {
    int v, rev;
    F flow;
    Edge() {}
    Edge(int _v, F _cap, F _flow, int _rev)
        : v(_v), flow(_flow - _cap), rev(_rev) {}
    inline bool sat() const { return flow >= 0; }
    inline bool unsat() const { return flow < 0; }
    inline F left() const { return -flow; }
    inline void addFlow(F x) { flow += x; }
  };
  vector<vector<Edge>> G;
  vector<int> layer, ptr;
  int n, second, t;
  Dinic(int _n) : n(_n) {
    G.resize(n);
    layer.resize(n);
  }
  void addEdge(int u, int v, F c) {
    int pu = signed(G[u].size()), pv = signed(G[v].size());
    G[u].push_back({v, c, 0, pv});
    G[v].push_back({u, 0, 0, pu});
  }
  bool buildBfsTree() {
    for (int i = 0; i < n; ++i) layer[i] = -1;
    queue<int> que({second});
    layer[second] = 0;
    while (signed(que.size())) {
      auto first = que.front();
      que.pop();
      if (first == t) break;
      for (auto i : G[first])
        if (layer[i.v] == -1 && i.unsat()) {
          layer[i.v] = layer[first] + 1;
          que.push(i.v);
        }
    }
    return layer[t] >= 0;
  }
  F sendFlow(int v, F first) {
    if (v == t) return first;
    for (; ptr[v] < signed(G[v].size()); ++ptr[v]) {
      Edge &e = G[v][ptr[v]];
      if (e.sat() || layer[e.v] != layer[v] + 1) continue;
      auto d = sendFlow(e.v, min(first, e.left()));
      if (d > 0) {
        e.addFlow(d);
        G[e.v][e.rev].addFlow(-d);
        return d;
      }
    }
    return 0;
  }
  F findFlow(int _s, int _t) {
    second = _s, t = _t;
    F ans = 0;
    while (buildBfsTree()) {
      ptr.assign(n, 0);
      if (F df = sendFlow(second, numeric_limits<F>::max())) ans += df;
    }
    return ans;
  }
};
void makeunique(vector<int> &x) {
  sort(x);
  x.resize(unique(x.begin(), x.end()) - x.begin());
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  int n, m;
  cin >> n >> m;
  vector<pair<pair<int, int>, pair<int, int>>> rect(m);
  for (auto &i : rect)
    cin >> i.first.first >> i.second.first >> i.first.second >> i.second.second;
  vector<int> x, y;
  for (auto &i : rect) {
    ++i.first.second;
    ++i.second.second;
    x.push_back(i.first.first);
    x.push_back(i.first.second);
    y.push_back(i.second.first);
    y.push_back(i.second.second);
  }
  makeunique(x);
  makeunique(y);
  Dinic<int> dinic(signed(x.size()) + signed(y.size()) + 2);
  int second = signed(x.size()) + signed(y.size());
  int t = second + 1;
  for (int i = 1; i < signed(x.size()); ++i)
    dinic.addEdge(second, i, x[i] - x[i - 1]);
  for (int i = 1; i < signed(y.size()); ++i)
    dinic.addEdge(signed(x.size()) + i, t, y[i] - y[i - 1]);
  for (int px = 1; px < signed(x.size()); ++px)
    for (int py = 1; py < signed(y.size()); ++py)
      for (auto i : rect) {
        if (i.first.first <= x[px - 1] && i.first.second >= x[px] &&
            i.second.first <= y[py - 1] && i.second.second >= y[py]) {
          dinic.addEdge(px, signed(x.size()) + py, 1000000007);
          break;
        }
      }
  cout << dinic.findFlow(second, t);
  return 0;
}