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;
const long long MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int n, m;
int x1[50], y22[50], x2[50], y2[50];
bool chk[111][111];
struct Edge {
  int to, r;
  Edge* ori;
  Edge* rev;
  Edge(int T, int R) { to = T, r = R; }
};
vector<Edge*> v[203];
void addedge(int f, int t, int r) {
  Edge* ori = new Edge(t, r);
  Edge* rev = new Edge(f, 0);
  ori->rev = rev;
  rev->rev = ori;
  v[f].push_back(ori);
  v[t].push_back(rev);
}
const int S = 201, T = 202;
int level[203], work[203];
bool bfs() {
  memset((level), -1, sizeof(level));
  ;
  level[S] = 0;
  queue<int> q;
  q.push(S);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (auto& nn : v[x]) {
      int next = nn->to;
      if (level[next] == -1 && nn->r > 0) {
        level[next] = level[x] + 1;
        q.push(next);
      }
    }
  }
  return level[T] != -1;
}
int dfs(int N, int des, int flow) {
  if (N == des) return flow;
  for (int& i = work[N]; i < v[N].size(); i++) {
    int next = v[N][i]->to;
    if (level[next] == level[N] + 1 && v[N][i]->r > 0) {
      int df = dfs(next, des, min(v[N][i]->r, flow));
      if (df > 0) {
        v[N][i]->r -= df;
        v[N][i]->rev->r += df;
        return df;
      }
    }
  }
  return 0;
}
int main() {
  vector<int> xx, yy;
  scanf("%d%d", &n, &m);
  for (int(i) = (0); (i) <= (m - 1); (i) += (1)) {
    scanf("%d%d%d%d", x1 + i, y22 + i, x2 + i, y2 + i);
    x2[i]++, y2[i]++;
    xx.push_back(x1[i]);
    xx.push_back(x2[i]);
    yy.push_back(y22[i]);
    yy.push_back(y2[i]);
  }
  sort(xx.begin(), xx.end());
  xx.resize(unique(xx.begin(), xx.end()) - xx.begin());
  sort(yy.begin(), yy.end());
  yy.resize(unique(yy.begin(), yy.end()) - yy.begin());
  int nx = xx.size(), ny = yy.size();
  for (int(i) = (0); (i) <= (m - 1); (i) += (1)) {
    x1[i] = lower_bound(xx.begin(), xx.end(), x1[i]) - xx.begin();
    x2[i] = lower_bound(xx.begin(), xx.end(), x2[i]) - xx.begin();
    y22[i] = lower_bound(yy.begin(), yy.end(), y22[i]) - yy.begin();
    y2[i] = lower_bound(yy.begin(), yy.end(), y2[i]) - yy.begin();
    for (int(ii) = (x1[i]); (ii) <= (x2[i] - 1); (ii) += (1))
      for (int(jj) = (y22[i]); (jj) <= (y2[i] - 1); (jj) += (1))
        chk[ii][jj] = 1;
  }
  for (int(i) = (0); (i) <= (nx - 2); (i) += (1))
    addedge(S, i, xx[i + 1] - xx[i]);
  for (int(i) = (0); (i) <= (ny - 2); (i) += (1))
    addedge(i + nx, T, yy[i + 1] - yy[i]);
  for (int(i) = (0); (i) <= (nx - 2); (i) += (1))
    for (int(j) = (0); (j) <= (ny - 2); (j) += (1)) {
      if (chk[i][j]) addedge(i, j + nx, 1987654321);
    }
  int ans = 0;
  while (bfs()) {
    memset((work), 0, sizeof(work));
    ;
    while (1) {
      int f = dfs(S, T, 1987654321);
      if (f == 0) break;
      ans += f;
    }
  }
  printf("%d\n", ans);
}