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;
inline long long mod(long long n, long long m) {
  long long ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}
long long gcd(long long a, long long b) {
  return (b == 0LL ? a : gcd(b, a % b));
}
long long exp(long long a, long long b, long long m) {
  if (b == 0LL) return 1LL;
  if (b == 1LL) return mod(a, m);
  long long k = mod(exp(a, b / 2, m), m);
  if (b & 1LL) {
    return mod(a * mod(k * k, m), m);
  } else
    return mod(k * k, m);
}
struct Dinic {
  struct Edge {
    int to, rev;
    long long c, oc;
    long long flow() { return max(oc - c, 0LL); }
  };
  vector<int> lvl, ptr, q;
  vector<vector<Edge>> adj;
  Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {}
  void addEdge(int a, int b, long long c, int rcap = 0) {
    adj[a].push_back({b, (int)adj[b].size(), c, c});
    adj[b].push_back({a, (int)adj[a].size() - 1, rcap, rcap});
  }
  long long dfs(int v, int t, long long f) {
    if (v == t || !f) return f;
    for (int& i = ptr[v]; i < (int)adj[v].size(); i++) {
      Edge& e = adj[v][i];
      if (lvl[e.to] == lvl[v] + 1)
        if (long long p = dfs(e.to, t, min(f, e.c))) {
          e.c -= p, adj[e.to][e.rev].c += p;
          return p;
        }
    }
    return 0;
  }
  long long calc(int s, int t) {
    long long flow = 0;
    q[0] = s;
    for (int L = 0; L < (31); ++L) do {
        lvl = ptr = vector<int>((int)q.size());
        int qi = 0, qe = lvl[s] = 1;
        while (qi < qe && !lvl[t]) {
          int v = q[qi++];
          for (auto& e : adj[v])
            if (!lvl[e.to] && e.c >> (30 - L))
              q[qe++] = e.to, lvl[e.to] = lvl[v] + 1;
        }
        while (long long p = dfs(s, t, LLONG_MAX)) flow += p;
      } while (lvl[t]);
    return flow;
  }
  bool leftOfMinCut(int a) { return lvl[a] != 0; }
};
const int inf = 1e9;
const int N = 55;
int x1[N], x2[N], abacaba[N], y2[N];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  vector<int> x, y;
  for (int i = 0; i < m; i++) {
    cin >> x1[i] >> abacaba[i] >> x2[i] >> y2[i];
    x1[i]--;
    abacaba[i]--;
    x.push_back(x1[i]);
    x.push_back(x2[i]);
    y.push_back(abacaba[i]);
    y.push_back(y2[i]);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  y.erase(unique(y.begin(), y.end()), y.end());
  int nx = (int)x.size(), ny = (int)y.size();
  int s = nx + ny + 100, t = nx + ny + 101;
  Dinic D(nx + ny + 200);
  for (int i = 1; i < nx; i++) {
    D.addEdge(s, i, x[i] - x[i - 1]);
  }
  for (int i = 1; i < ny; i++) {
    D.addEdge(nx + i, t, y[i] - y[i - 1]);
  }
  auto inside = [](int a, int b, int i, int j) { return (a <= i and j <= b); };
  for (int i = 1; i < nx; i++) {
    for (int j = 1; j < ny; j++) {
      int ok = 0;
      for (int k = 0; k < m; k++) {
        if (inside(x1[k], x2[k], x[i - 1], x[i]) and
            inside(abacaba[k], y2[k], y[j - 1], y[j])) {
          ok = 1;
          break;
        }
      }
      if (ok) {
        D.addEdge(i, nx + j, inf);
      }
    }
  }
  cout << D.calc(s, t) << "\n";
}