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;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using P = pair<ll, ll>;
constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());
class ERectanglePainting2 {
 public:
  struct {
    struct edge {
      int to;
      ll cost;
      int rev;
    };
    int N;
    vector<vector<edge>> graph;
    vector<int> level;
    vector<int> iter;
    void init(int n) {
      graph.resize(n + 1, vector<edge>());
      level.resize(n + 1);
      iter.resize(n + 1);
      N = n + 1;
    }
    void add_edge(int from, int to, ll cost) {
      int r1 = graph[from].size();
      int r2 = graph[to].size();
      graph[from].push_back((edge){to, cost, r2});
      graph[to].push_back((edge){from, 0, r1});
    }
    void bfs(int s) {
      for (int i = 0; i < N; i++) level[i] = -1;
      queue<int> que;
      level[s] = 0;
      que.push(s);
      while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (auto& e : graph[v]) {
          if (e.cost > 0 && level[e.to] < 0) {
            level[e.to] = level[v] + 1;
            que.push(e.to);
          }
        }
      }
    }
    ll dfs(int v, int t, ll f) {
      if (v == t) return f;
      for (int& i = iter[v]; i < graph[v].size(); i++) {
        iter[v] = i;
        edge& e = graph[v][i];
        if (e.cost > 0 && level[v] < level[e.to]) {
          ll d = dfs(e.to, t, min(f, e.cost));
          if (d > 0) {
            e.cost -= d;
            graph[e.to][e.rev].cost += d;
            return d;
          }
        }
      }
      return 0;
    }
    ll max_flow(int s, int t) {
      ll flow = 0;
      while (true) {
        bfs(s);
        if (level[t] < 0) return flow;
        for (int i = 0; i < N; i++) iter[i] = 0;
        ll f;
        while ((f = dfs(s, t, LLONG_MAX / 4)) > 0) {
          flow += f;
        }
      }
    }
  } D;
  void solve(istream& cin, ostream& cout) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    if (m == 0) {
      cout << 0 << endl;
      return;
    }
    vector<int> x1(m), x2(m), y1(m), y2(m);
    set<int> xst, yst;
    for (int i = 0; i < (int)(m); i++) {
      cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      xst.insert(x1[i]);
      xst.insert(x2[i] + 1);
      yst.insert(y1[i]);
      yst.insert(y2[i] + 1);
    }
    unordered_map<int, int> xmp;
    vector<int> xmpv;
    int idx = 0;
    for (auto e : xst) {
      xmp[e] = idx;
      xmpv.push_back(e);
      idx++;
    }
    int xcnt = idx;
    idx = 0;
    unordered_map<int, int> ymp;
    vector<int> ympv;
    for (auto e : yst) {
      ymp[e] = idx;
      ympv.push_back(e);
      idx++;
    }
    int ycnt = idx;
    vector<vector<int>> mat(xcnt, vector<int>(ycnt));
    for (int i = 0; i < (int)(m); i++) {
      42;
      for (int x = xmp[x1[i]]; x < xmp[x2[i] + 1]; x++) {
        for (int y = ymp[y1[i]]; y < ymp[y2[i] + 1]; y++) {
          mat[x][y] = 1;
        }
      }
    }
    D.init(xcnt + ycnt + 2);
    int st = xcnt + ycnt + 1;
    int go = xcnt + ycnt + 2;
    for (int i = 0; i < (int)(xcnt - 1); i++) {
      D.add_edge(st, i, xmpv[i + 1] - xmpv[i]);
    }
    for (int j = 0; j < (int)(ycnt - 1); j++) {
      D.add_edge(xcnt + j, go, ympv[j + 1] - ympv[j]);
    }
    for (int i = 0; i < (int)(xcnt); i++) {
      for (int j = 0; j < (int)(ycnt); j++) {
        if (mat[i][j]) {
          D.add_edge(i, xcnt + j, LLONG_MAX / 4);
        }
      }
    }
    cout << D.max_flow(st, go) << endl;
  }
};
signed main() {
  ERectanglePainting2 solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}