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")
using namespace std;
int in() {
  int x;
  cin >> x;
  return x;
}
long long lin() {
  long long x;
  cin >> x;
  return x;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline void print(pair<T, T> p) {
  cout << "(" << p.first << "," << p.second << ") ";
}
template <class T>
inline void print(vector<pair<T, T>> v) {
  for (auto e : v) print(e);
  cout << "\n";
}
template <class T>
inline void print(T v) {
  for (auto e : v) cout << e << " ";
  cout << "\n";
}
void go();
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int Testcases = 1;
  while (Testcases--) {
    go();
  }
  return 0;
}
struct sq {
  int a, b, c, d;
};
template <typename flow_t>
struct Dinic {
  const flow_t INF;
  struct edge {
    int to;
    flow_t cap;
    int rev;
    bool isrev;
    int idx;
  };
  vector<vector<edge>> graph;
  vector<int> min_cost, iter;
  Dinic(int V) : INF(numeric_limits<flow_t>::max()), graph(V) {}
  void add_edge(int from, int to, flow_t cap, int idx = -1) {
    graph[from].emplace_back(
        (edge){to, cap, (int)graph[to].size(), false, idx});
    graph[to].emplace_back(
        (edge){from, 0, (int)graph[from].size() - 1, true, idx});
  }
  bool bfs(int s, int t) {
    min_cost.assign(graph.size(), -1);
    queue<int> que;
    min_cost[s] = 0;
    que.push(s);
    while (!que.empty() && min_cost[t] == -1) {
      int p = que.front();
      que.pop();
      for (auto &e : graph[p]) {
        if (e.cap > 0 && min_cost[e.to] == -1) {
          min_cost[e.to] = min_cost[p] + 1;
          que.push(e.to);
        }
      }
    }
    return min_cost[t] != -1;
  }
  flow_t dfs(int idx, const int t, flow_t flow) {
    if (idx == t) return flow;
    for (int &i = iter[idx]; i < graph[idx].size(); i++) {
      edge &e = graph[idx][i];
      if (e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
        flow_t d = dfs(e.to, t, min(flow, e.cap));
        if (d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  flow_t max_flow(int s, int t) {
    flow_t flow = 0;
    while (bfs(s, t)) {
      iter.assign(graph.size(), 0);
      flow_t f = 0;
      while ((f = dfs(s, t, INF)) > 0) flow += f;
    }
    return flow;
  }
  void output() {
    for (int i = 0; i < graph.size(); i++) {
      for (auto &e : graph[i]) {
        if (e.isrev) continue;
        auto &rev_e = graph[e.to][e.rev];
        cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/"
             << e.cap + rev_e.cap << ")"
             << "\n";
      }
    }
  }
};
void go() {
  int n = in();
  int m = in();
  if (m == 0) {
    cout << 0 << "\n";
    return;
  }
  set<int> xx, yy;
  map<int, int> x, y;
  vector<sq> v;
  for (long long i = 0; i < m; i++) {
    int a = in(), b = in(), c = in() + 1, d = in() + 1;
    v.push_back(sq{a, b, c, d});
    xx.insert(a);
    xx.insert(c);
    yy.insert(b);
    yy.insert(d);
  }
  int id = 0;
  vector<int> revx, revy;
  for (auto e : xx) x[e] = id++, revx.push_back(e);
  id = 0;
  for (auto e : yy) y[e] = id++, revy.push_back(e);
  Dinic<long long> g(2 + x.size() + y.size() + 10);
  for (auto s : v) {
    for (long long i = x[s.a]; i <= x[s.c] - 1; ++i) {
      for (long long j = y[s.b]; j <= y[s.d] - 1; ++j) {
        g.add_edge(i + 1, x.size() + j, 1e9);
      }
    }
  }
  for (long long i = 0; i < revx.size() - 1; i++) {
    g.add_edge(0, i + 1, revx[i + 1] - revx[i]);
  }
  for (long long i = 0; i < revy.size() - 1; i++) {
    g.add_edge(x.size() + i, x.size() + y.size() + 1, revy[i + 1] - revy[i]);
  }
  cout << g.max_flow(0, x.size() + y.size() + 1) << "\n";
}