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;
using ll = long long;
const int EDGE_COUNT = (int)1e5;
const int VERTEX_COUNT = (int)1e3;
const ll INF = (ll)1e15;
struct edge {
  ll c, f;
  int w;
} e[EDGE_COUNT];
vector<int> g[VERTEX_COUNT];
int efree;
int n, m, k;
int start, finish;
bool was[VERTEX_COUNT];
set<int> xs, ys;
map<int, int> xnum, ynum;
int x1[VERTEX_COUNT];
int y18597[VERTEX_COUNT];
int x2[VERTEX_COUNT];
int y23764[VERTEX_COUNT];
int wx[VERTEX_COUNT];
int wy[VERTEX_COUNT];
void add_edge(int a, int b, ll c) {
  e[efree].w = b;
  e[efree].c = c;
  e[efree].f = 0;
  g[a].push_back(efree++);
  e[efree].w = a;
  e[efree].c = 0;
  e[efree].f = 0;
  g[b].push_back(efree++);
}
ll dfs(int v, ll flow) {
  if (flow == 0) return 0;
  was[v] = true;
  if (v == finish) return flow;
  for (int i : g[v]) {
    if (was[e[i].w]) continue;
    ll tmp = dfs(e[i].w, min(flow, e[i].c - e[i].f));
    if (tmp) {
      e[i].f += tmp;
      e[i ^ 1].f = -e[i].f;
      return tmp;
    }
  }
  return 0;
}
void dbg() {
  cout << "start=" << start << endl;
  cout << "finish=" << finish << endl;
  cout << xnum[3] << endl;
  cout << xnum[5] << endl;
  auto it = xs.begin();
  for (int i = 0; i < xs.size(); ++i, it++) {
    cout << "i=" << i << " " << wx[i] << "  x=" << *it << endl;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> x1[i] >> y18597[i] >> x2[i] >> y23764[i];
    x2[i]++;
    y23764[i]++;
    xs.insert(x1[i]);
    xs.insert(x2[i]);
    ys.insert(y18597[i]);
    ys.insert(y23764[i]);
  }
  k = 0;
  for (int i : xs) {
    if (k) wx[k - 1] += i;
    wx[k] -= i;
    xnum[i] = k++;
  }
  k = 0;
  for (int i : ys) {
    if (k) wy[k - 1] += i;
    wy[k] -= i;
    ynum[i] = k++;
  }
  start = 0;
  finish = xs.size() + ys.size() + 1;
  for (int i = 0; i < m; ++i) {
    x1[i] = xnum[x1[i]];
    x2[i] = xnum[x2[i]];
    y18597[i] = ynum[y18597[i]];
    y23764[i] = ynum[y23764[i]];
    for (int tx = x1[i]; tx < x2[i]; ++tx)
      for (int ty = y18597[i]; ty < y23764[i]; ++ty) {
        add_edge(1 + tx, xnum.size() + ty + 1, INF);
      }
  }
  k = 0;
  for (auto p : xnum) {
    if (wx[k] > 0) add_edge(start, k + 1, wx[k]);
    k++;
  }
  k = 0;
  for (auto p : ynum) {
    if (wy[k] > 0) add_edge(xnum.size() + k + 1, finish, wy[k]);
    k++;
  }
  while (k = dfs(start, INF)) {
    fill(was, was + finish + 1, false);
  }
  ll ans = 0;
  for (int i : g[start]) ans += e[i].f;
  cout << ans << endl;
}