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 INF = 1e14;
template <class T>
struct Edge {
  long long from, to, index;
  T cap, flow;
  Edge(long long from, long long to, T cap, T flow, long long index)
      : from(from), to(to), cap(cap), flow(flow), index(index) {}
};
template <class T>
struct PushRelabel {
  long long n;
  vector<vector<Edge<T>>> adj;
  vector<T> excess;
  vector<long long> dist, count;
  vector<bool> active;
  vector<vector<long long>> B;
  long long b;
  queue<long long> Q;
  PushRelabel(long long n) : n(n), adj(n) {}
  void AddEdge(long long from, long long to, long long cap) {
    adj[from].push_back(Edge<T>(from, to, cap, 0, adj[to].size()));
    if (from == to) {
      adj[from].back().index++;
    }
    adj[to].push_back(Edge<T>(to, from, 0, 0, adj[from].size() - 1));
  }
  void Enqueue(long long v) {
    if (!active[v] && excess[v] > 0 && dist[v] < n) {
      active[v] = true;
      B[dist[v]].push_back(v);
      b = max(b, dist[v]);
    }
  }
  void Push(Edge<T> &e) {
    T amt = min(excess[e.from], e.cap - e.flow);
    if (dist[e.from] == dist[e.to] + 1 && amt > T(0)) {
      e.flow += amt;
      adj[e.to][e.index].flow -= amt;
      excess[e.to] += amt;
      excess[e.from] -= amt;
      Enqueue(e.to);
    }
  }
  void Gap(long long k) {
    for (long long v = 0; v < n; v++)
      if (dist[v] >= k) {
        count[dist[v]]--;
        dist[v] = max(dist[v], n);
        count[dist[v]]++;
        Enqueue(v);
      }
  }
  void Relabel(long long v) {
    count[dist[v]]--;
    dist[v] = n;
    for (auto e : adj[v])
      if (e.cap - e.flow > 0) {
        dist[v] = min(dist[v], dist[e.to] + 1);
      }
    count[dist[v]]++;
    Enqueue(v);
  }
  void Discharge(long long v) {
    for (auto &e : adj[v]) {
      if (excess[v] > 0) {
        Push(e);
      } else {
        break;
      }
    }
    if (excess[v] > 0) {
      if (count[dist[v]] == 1) {
        Gap(dist[v]);
      } else {
        Relabel(v);
      }
    }
  }
  T GetMaxFlow(long long s, long long t) {
    dist = vector<long long>(n, 0), excess = vector<T>(n, 0),
    count = vector<long long>(n + 1, 0), active = vector<bool>(n, false),
    B = vector<vector<long long>>(n), b = 0;
    for (auto &e : adj[s]) {
      excess[s] += e.cap;
    }
    count[0] = n;
    Enqueue(s);
    active[t] = true;
    while (b >= 0) {
      if (!B[b].empty()) {
        long long v = B[b].back();
        B[b].pop_back();
        active[v] = false;
        Discharge(v);
      } else {
        b--;
      }
    }
    return excess[t];
  }
  T GetMinCut(long long s, long long t, vector<long long> &cut);
};
inline bool contains(vector<vector<long long>> &v,
                     const vector<long long> &v2) {
  for (auto &i : v) {
    if (i[0] <= v2[0] && i[1] <= v2[1] && i[2] >= v2[2] && i[3] >= v2[3])
      return true;
  }
  return false;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, x1, y1, x2, y2;
  cin >> n >> m;
  vector<long long> hor, ver;
  vector<vector<long long>> v(m);
  for (long long i = 0; i < m; i++) {
    cin >> x1 >> y1 >> x2 >> y2;
    x2++;
    y2++;
    v[i] = {x1, y1, x2, y2};
    hor.push_back(x1);
    hor.push_back(x2);
    ver.push_back(y1);
    ver.push_back(y2);
  }
  sort(hor.begin(), hor.end());
  hor.erase(unique(hor.begin(), hor.end()), hor.end());
  sort(ver.begin(), ver.end());
  ver.erase(unique(ver.begin(), ver.end()), ver.end());
  PushRelabel<long long> flow(hor.size() + ver.size() + 10);
  long long source = hor.size() + ver.size();
  long long sink = hor.size() + ver.size() + 1;
  for (long long i = 1; i < hor.size(); i++) {
    flow.AddEdge(source, i, hor[i] - hor[i - 1]);
  }
  for (long long i = 1; i < ver.size(); i++) {
    flow.AddEdge(hor.size() + i, sink, ver[i] - ver[i - 1]);
  }
  for (long long i = 1; i < hor.size(); i++) {
    for (long long j = 1; j < ver.size(); j++) {
      if (contains(v, {hor[i - 1], ver[j - 1], hor[i], ver[j]})) {
        flow.AddEdge(i, hor.size() + j, INF);
      }
    }
  }
  cout << flow.GetMaxFlow(source, sink);
  return 0;
}