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;
struct Rect {
  int x1;
  int y1;
  int x2;
  int y2;
  friend istream& operator>>(istream& in, Rect& x) {
    in >> x.x1 >> x.y1 >> x.x2 >> x.y2;
    --x.x1;
    --x.y1;
    return in;
  }
};
template <typename T>
T load() {
  T r;
  cin >> r;
  return r;
}
template <typename T>
vector<T> loadMany(int n) {
  vector<T> rs(n);
  generate(rs.begin(), rs.end(), &load<T>);
  return rs;
}
template <typename T>
struct Scaler {
  struct Build {
    vector<T> xs;
    void notice(const T& x) { xs.push_back(x); }
    Scaler prepare() {
      sort(xs.begin(), xs.end());
      xs.erase(unique(xs.begin(), xs.end()), xs.end());
      return {move(xs)};
    }
  };
  int scale(const T& x) const {
    return (int)(lower_bound(xs.begin(), xs.end(), x) - xs.begin());
  }
  const T& unscale(int i) const { return xs[i]; }
  int size() const { return (int)xs.size(); }
  vector<T> xs;
};
template <typename T, T oo>
struct FlowGraph {
  struct Edge {
    int dest;
    unique_ptr<T> cap;
    T* revCap;
  };
  FlowGraph(int n) : edges(n) {}
  T* addEdge(int v, int u, T capacity) {
    edges[v].push_back(Edge{u, unique_ptr<T>(new T(capacity)), nullptr});
    edges[u].push_back(
        Edge{v, unique_ptr<T>(new T(0)), edges[v].back().cap.get()});
    edges[v].back().revCap = edges[u].back().cap.get();
    return edges[v].back().cap.get();
  }
  void dinic(int source, int sink) {
    while (true) {
      auto dist = dinicBFS(source);
      if (dist[sink] == -1) break;
      auto next = vector<int>(edges.size(), 0);
      dinicPush(source, +oo, sink, next, dist);
    }
  }
  vector<int> dinicBFS(int source) {
    auto dist = vector<int>(edges.size(), -1);
    dist[source] = 0;
    auto que = vector<int>({source});
    for (auto i = 0; i < (int)que.size(); ++i) {
      for (auto& edge : edges[que[i]]) {
        if (*edge.cap == 0) continue;
        if (dist[edge.dest] != -1) continue;
        dist[edge.dest] = dist[que[i]] + 1;
        que.push_back(edge.dest);
      }
    }
    return dist;
  }
  int dinicPush(int v, int wave, int sink, vector<int>& next,
                const vector<int>& dist) {
    if (wave == 0 or v == sink) return wave;
    auto total = 0;
    for (auto& i = next[v]; i < (int)edges[v].size(); ++i) {
      auto& edge = edges[v][i];
      if (dist[v] + 1 != dist[edge.dest]) continue;
      auto piped = dinicPush(edge.dest, min(wave, *edge.cap), sink, next, dist);
      wave -= piped;
      *edge.cap -= piped;
      *edge.revCap += piped;
      total += piped;
      if (wave == 0) break;
    }
    return total;
  }
  template <typename F>
  void onCut(int source, F f) {
    auto que = vector<int>({source});
    auto visit = vector<bool>(edges.size(), false);
    visit[source] = true;
    for (auto i = 0; i < (int)que.size(); ++i)
      for (auto& edge : edges[que[i]])
        if (*edge.cap != 0 and not visit[edge.dest])
          que.push_back(edge.dest), visit[edge.dest] = true;
    for (auto v : que)
      for (auto& edge : edges[v])
        if (*edge.cap == 0 and not visit[edge.dest]) f(v, edge.dest);
  }
  int size() const { return (int)edges.size(); }
  vector<vector<Edge>> edges;
};
array<Scaler<int>, 2> prepareRectScalers(const vector<Rect>& rects) {
  auto bx = Scaler<int>::Build{};
  auto by = Scaler<int>::Build{};
  for (auto& rect : rects) {
    bx.notice(rect.x1);
    bx.notice(rect.x2);
    by.notice(rect.y1);
    by.notice(rect.y2);
  }
  return array<Scaler<int>, 2>{bx.prepare(), by.prepare()};
}
void scaleRects(vector<Rect>& rects, const Scaler<int>& sx,
                const Scaler<int>& sy) {
  for (auto& rect : rects) {
    rect.x1 = sx.scale(rect.x1);
    rect.x2 = sx.scale(rect.x2);
    rect.y1 = sy.scale(rect.y1);
    rect.y2 = sy.scale(rect.y2);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  load<int>();
  auto m = load<int>();
  auto rects = loadMany<Rect>(m);
  auto ss = prepareRectScalers(rects);
  auto& sx = ss[0];
  auto& sy = ss[1];
  scaleRects(rects, sx, sy);
  auto cx = [&](int x) { return sx.unscale(x + 1) - sx.unscale(x); };
  auto cy = [&](int y) { return sy.unscale(y + 1) - sy.unscale(y); };
  auto grid = vector<vector<bool>>(sx.size(), vector<bool>(sy.size(), false));
  for (auto rect : rects)
    for (auto x = rect.x1; x < rect.x2; ++x)
      for (auto y = rect.y1; y < rect.y2; ++y) grid[x][y] = true;
  auto graph =
      FlowGraph<int, numeric_limits<int>::max()>(2 + sx.size() + sy.size());
  for (auto x = 0; x < sx.size() - 1; ++x)
    graph.addEdge(graph.size() - 2, x, cx(x));
  for (auto y = 0; y < sy.size() - 1; ++y)
    graph.addEdge(sx.size() + y, graph.size() - 1, cy(y));
  for (auto x = 0; x < sx.size(); ++x)
    for (auto y = 0; y < sy.size(); ++y)
      if (grid[x][y])
        graph.addEdge(x, sx.size() + y, numeric_limits<int>::max());
  graph.dinic(graph.size() - 2, graph.size() - 1);
  auto cost = 0;
  graph.onCut(graph.size() - 2, [&](int v, int u) {
    if (v == graph.size() - 2)
      cost += cx(u);
    else if (u == graph.size() - 1)
      cost += cy(v - sx.size());
  });
  cout << cost << '\n';
}