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;
long long src, snk;
long long cur;
long long vis[1004];
const long long inf = 1e9;
class edge {
 public:
  long long to, c, f;
  edge(){};
  edge(long long tt, long long cc, long long ff) {
    to = tt;
    c = cc;
    f = ff;
  }
};
vector<edge> e;
vector<long long> g[5005];
void addedge(long long u, long long v, long long ca) {
  g[u].push_back(e.size());
  edge nw(v, ca, 0);
  e.push_back(nw);
  g[v].push_back(e.size());
  edge nww(u, 0, 0);
  e.push_back(nww);
}
long long dfs(long long s, long long k) {
  if (s == snk) return k;
  vis[s] = cur;
  for (auto i : g[s]) {
    long long to = e[i].to;
    long long cap = e[i].c;
    long long flo = e[i].f;
    if (vis[to] != cur) {
      if ((cap - flo) >= k) {
        long long nxt = dfs(to, k);
        if (nxt > 0) {
          e[i].f += nxt;
          e[(i ^ 1)].f -= nxt;
          return nxt;
        }
      }
    }
  }
  return 0;
}
long long enlarge(long long k) {
  long long ret = 0;
  while (1) {
    ++cur;
    long long h = dfs(src, k);
    ret += h;
    if (h == 0) break;
  }
  return ret;
}
long long flow() {
  long long ret = 0LL;
  for (long long i = (1LL << 30); i > 0; i = (i >> 1)) {
    ret += enlarge(i);
  }
  return ret;
}
bool ok[1003][2004];
long long n, m;
long long x1[55], y3[55], x2[55], y2[55];
vector<long long> xx, yy;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  if (m == 0) {
    cout << "0\n";
    return 0;
  }
  for (long long i = 1; i <= m; i++) {
    cin >> x1[i] >> y3[i] >> x2[i] >> y2[i];
    x2[i]++;
    y2[i]++;
    xx.push_back(x1[i]);
    xx.push_back(x2[i]);
    yy.push_back(y3[i]);
    yy.push_back(y2[i]);
  }
  sort(xx.begin(), xx.end());
  sort(yy.begin(), yy.end());
  long long sz = unique(xx.begin(), xx.end()) - xx.begin();
  xx.resize(sz);
  sz = unique(yy.begin(), yy.end()) - yy.begin();
  yy.resize(sz);
  src = 1;
  snk = 2;
  long long sh = 3;
  long long sh2 = xx.size() + 10;
  for (long long i = 0; i < xx.size() - 1; i++) {
    addedge(src, sh + i, xx[i + 1] - xx[i]);
  }
  for (long long i = 0; i < yy.size() - 1; i++) {
    addedge(sh2 + i, snk, yy[i + 1] - yy[i]);
  }
  for (long long j = 1; j <= m; j++) {
    long long sx, ex, sy, ey;
    for (long long i = 0; i < xx.size(); i++) {
      if (xx[i] == x1[j]) {
        sx = i;
        break;
      }
    }
    for (long long i = 0; i < yy.size(); i++) {
      if (yy[i] == y3[j]) {
        sy = i;
        break;
      }
    }
    for (long long i = 0; i < xx.size(); i++) {
      if (xx[i] == x2[j]) {
        ex = i - 1;
        break;
      }
    }
    for (long long i = 0; i < yy.size(); i++) {
      if (yy[i] == y2[j]) {
        ey = i - 1;
        break;
      }
    }
    for (long long x = sx; x <= ex; x++)
      for (long long y = sy; y <= ey; y++) ok[x][y] = true;
  }
  for (long long i = 0; i < xx.size(); i++) {
    for (long long j = 0; j < yy.size(); j++) {
      if (ok[i][j]) {
        addedge(i + sh, j + sh2, inf);
      }
    }
  }
  cout << flow() << endl;
  return 0;
}