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 int N = 105;
vector<int> x(2), y(2);
void makeu(vector<int>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  assert(v.size() < N);
}
struct TEdge {
  int from, to;
  long long capacity, flow;
  TEdge* reverse;
};
TEdge edgePool[1000000];
int edgePoolPtr = 0;
typedef vector<TEdge*> ve;
vector<ve> edges;
int SOURCE, TARGET;
TEdge* AddEdge(int from, int to, long long capacity) {
  TEdge* e1 = &edgePool[edgePoolPtr++];
  TEdge* e2 = &edgePool[edgePoolPtr++];
  TEdge fw = {from, to, capacity, 0, e2};
  TEdge bw = {to, from, 0, 0, e1};
  *e1 = fw;
  *e2 = bw;
  edges[from].push_back(e1);
  edges[to].push_back(e2);
  return e1;
}
inline long long AvailableCapacity(const TEdge* p) {
  return (p->capacity - p->flow);
}
class TDinic {
 public:
  vector<int> Distances;
  vector<size_t> Ptr;
  int N;
  void BFS() {
    deque<int> q;
    Distances.assign(N, -1);
    Distances[SOURCE] = 0;
    q.push_back(SOURCE);
    while (!q.empty()) {
      int p = q.front();
      q.pop_front();
      for (size_t i = 0; i < edges[p].size(); i++) {
        if (!AvailableCapacity(edges[p][i])) continue;
        int c = edges[p][i]->to;
        if (Distances[c] == -1) {
          Distances[c] = Distances[p] + 1;
          q.push_back(c);
        }
      }
    }
  }
  long long DFS(int p, long long fl) {
    if (fl == 0) return 0;
    if (p == TARGET) return fl;
    long long res = 0;
    for (size_t& i = Ptr[p]; Ptr[p] < edges[p].size() && fl != 0; ++i) {
      if (!AvailableCapacity(edges[p][i])) {
        continue;
      }
      if (Distances[edges[p][i]->from] + 1 != Distances[edges[p][i]->to])
        continue;
      long long pushed =
          DFS(edges[p][i]->to, min(fl, AvailableCapacity(edges[p][i])));
      fl -= pushed;
      res += pushed;
      edges[p][i]->flow += pushed;
      edges[p][i]->reverse->flow -= pushed;
      if (fl == 0) break;
    }
    return res;
  }
  long long calc_max_flow() {
    N = (int)edges.size();
    long long res = 0;
    while (true) {
      BFS();
      Ptr.assign(N, 0);
      long long p = DFS(SOURCE, 1e18);
      if (!p) break;
      res += p;
    }
    return res;
  }
};
const int DEBUG = 0;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n = 1e9, m = 50;
  if (!DEBUG) cin >> n >> m;
  x[1] = y[1] = n;
  vector<array<int, 4>> rect;
  for (int i = 0; i < m; ++i) {
    int a, b, c, d;
    if (!DEBUG) {
      cin >> a >> b >> c >> d;
      --a;
      --b;
      --c;
      --d;
    } else {
      a = rand() % n;
      b = rand() % n;
      c = rand() % n;
      d = rand() % n;
      if (a > c) swap(a, c);
      if (b > d) swap(b, d);
    }
    x.push_back(a);
    x.push_back(c + 1);
    y.push_back(b);
    y.push_back(d + 1);
    rect.push_back({a, b, c + 1, d + 1});
  }
  makeu(x);
  makeu(y);
  SOURCE = x.size() + y.size();
  TARGET = SOURCE + 1;
  edges.clear();
  edgePoolPtr = 0;
  edges.resize(TARGET + 1);
  for (int i = 0; i < (int)x.size(); ++i) {
    AddEdge(SOURCE, i, x[i + 1] - x[i]);
  }
  for (int i = 0; i < (int)y.size(); ++i) {
    AddEdge(i + x.size(), TARGET, y[i + 1] - y[i]);
  }
  for (auto v : rect) {
    int x1 = lower_bound(x.begin(), x.end(), v[0]) - x.begin();
    int y1 = lower_bound(y.begin(), y.end(), v[1]) - y.begin();
    int x2 = lower_bound(x.begin(), x.end(), v[2]) - x.begin();
    int y2 = lower_bound(y.begin(), y.end(), v[3]) - y.begin();
    for (int i = x1; i < x2; ++i)
      for (int j = y1; j < y2; ++j) {
        AddEdge(i, x.size() + j, n);
      }
  }
  TDinic f;
  cout << f.calc_max_flow() << endl;
  return 0;
}