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;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T1, typename T2>
inline void chkmin(T1 &x, const T2 &y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, const T2 &y) {
  if (x < y) x = y;
}
struct edge {
  ll to, cap, flow;
  edge() {}
  edge(ll _to, ll _cap) { to = _to, cap = _cap, flow = 0; }
  ll get_cap() { return cap - flow; }
};
struct max_flow {
  vector<edge> Edge;
  vector<vector<ll>> g;
  ll n;
  ll s, f;
  max_flow() {}
  void add_edge(ll from, ll to, ll cap) {
    g[from].push_back(Edge.size());
    Edge.push_back({to, cap});
    g[to].push_back(Edge.size());
    Edge.push_back({from, 0});
  }
  max_flow(ll _n, ll _s, ll _f) {
    n = _n, s = _s, f = _f;
    g.assign(n, {});
    Edge.clear();
  }
  vector<ll> dist;
  queue<ll> q;
  const ll INF = 1e9 + 10;
  bool bfs() {
    dist.assign(n, INF);
    dist[s] = 0;
    q.push(s);
    while (!q.empty()) {
      ll v = q.front();
      q.pop();
      for (auto i : g[v]) {
        if (Edge[i].get_cap() < 1) continue;
        ll to = Edge[i].to;
        if (dist[to] != INF) continue;
        dist[to] = dist[v] + 1;
        q.push(to);
      }
    }
    return dist[f] != INF;
  }
  vector<ll> pos;
  ll dfs(ll v, ll flow) {
    if (v == f) return flow;
    for (; pos[v] < g[v].size(); pos[v]++) {
      ll ind = g[v][pos[v]];
      if (Edge[ind].get_cap() < 1) continue;
      ll to = Edge[ind].to;
      if (dist[to] != dist[v] + 1) continue;
      ll add = dfs(to, min(flow, Edge[ind].get_cap()));
      if (add) {
        Edge[ind].flow += add;
        Edge[ind ^ 1].flow -= add;
        return add;
      }
    }
    return 0;
  }
  ll get_flow() {
    ll ans = 0;
    while (bfs()) {
      pos.assign(n, 0);
      while (true) {
        ll add = dfs(s, INF);
        ans += add;
        if (!add) break;
      }
    }
    return ans;
  }
};
const ll MAXM = 51;
ll n, m;
ll x1228[MAXM], y1228[MAXM], x2[MAXM], y2[MAXM];
vector<ll> x, y;
void read() {
  cin >> n >> m;
  for (ll i = 0; i < m; i++) {
    cin >> x1228[i] >> y1228[i] >> x2[i] >> y2[i];
    x2[i]++;
    y2[i]++;
    x.push_back(x1228[i]);
    x.push_back(x2[i]);
    y.push_back(y1228[i]);
    y.push_back(y2[i]);
  }
}
ll ans;
void run() {
  sort(x.begin(), x.end());
  x.resize(unique(x.begin(), x.end()) - x.begin());
  sort(y.begin(), y.end());
  y.resize(unique(y.begin(), y.end()) - y.begin());
  max_flow g(x.size() + y.size() + 2, x.size() + y.size(),
             x.size() + y.size() + 1);
  for (ll i = 0; i < (ll)x.size() - 1; i++) {
    g.add_edge(g.s, i, x[i + 1] - x[i]);
  }
  for (ll i = 0; i < (ll)y.size() - 1; i++) {
    g.add_edge(i + x.size(), g.f, y[i + 1] - y[i]);
  }
  for (ll el = 0; el < m; el++) {
    for (ll i = 0; i < (ll)x.size() - 1; i++) {
      for (ll j = 0; j < (ll)y.size() - 1; j++) {
        if (x1228[el] <= x[i] && x[i + 1] <= x2[el] && y1228[el] <= y[j] &&
            y[j + 1] <= y2[el])
          g.add_edge(i, j + x.size(), (x[i + 1] - x[i]) + (y[j + 1] - y[j]));
      }
    }
  }
  ans = g.get_flow();
}
void write() { cout << ans << endl; }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  read();
  run();
  write();
  return 0;
}