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 int inf = 1e9 + 9;
const int mod = 998244353;
const long long int MOD = 1e9 + 696969;
const long long INF = 1e18 + 3;
set<int> xlines;
set<int> ylines;
namespace mincost {
const int V = 101000, E = 10010000, _inf = INT_MAX;
int dis[V], q[V * 30], vis[V], fst[V], pre[V], nxt[E], y[E], f[E], c[E], S, T,
    flow, cost, tot, tn;
void init(int s, int t, int Tn) {
  tot = 1;
  tn = Tn;
  for (int i = 0; i < tn; i++) fst[i] = 0;
  S = s;
  T = t;
}
void add(int u, int v, int ff, int cc) {
  tot++;
  y[tot] = v;
  nxt[tot] = fst[u];
  f[tot] = ff;
  c[tot] = cc;
  fst[u] = tot;
  tot++;
  y[tot] = u;
  nxt[tot] = fst[v];
  f[tot] = 0;
  c[tot] = -cc;
  fst[v] = tot;
}
bool spfa() {
  for (int i = 0; i < tn; i++) dis[i] = inf, vis[i] = 0, pre[i] = 0;
  dis[S] = 0;
  q[0] = S;
  vis[S] = 1;
  int t = 1;
  for (int i = 0; i < t; i++) {
    int u = q[i];
    for (int j = fst[u]; j; j = nxt[j]) {
      int v = y[j];
      if (f[j] && dis[v] > dis[u] + c[j]) {
        dis[v] = dis[u] + c[j];
        pre[v] = j;
        if (!vis[v]) vis[v] = 1, q[t++] = v;
      }
    }
    vis[u] = 0;
  }
  return dis[T] != inf;
}
void augment() {
  int p = T, _f = inf;
  while (pre[p]) _f = min(_f, f[pre[p]]), p = y[pre[p] ^ 1];
  flow += _f;
  cost += _f * dis[T];
  p = T;
  while (pre[p]) f[pre[p]] -= _f, f[pre[p] ^ 1] += _f, p = y[pre[p] ^ 1];
}
void solve() {
  flow = 0, cost = 0;
  while (spfa()) augment();
}
}  // namespace mincost
int X1[51], X2[51], Y1[51], Y2[51], n, m;
vector<int> x, y;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = (1); i <= (m); ++i) {
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    X1[i] = x1;
    X2[i] = x2;
    Y1[i] = y1;
    Y2[i] = y2;
    xlines.insert(x1);
    if (x1 > 1) xlines.insert(x1 - 1);
    xlines.insert(x2);
    if (x2 < n) xlines.insert(x2 + 1);
    ylines.insert(y1);
    if (y1 > 1) ylines.insert(y1 - 1);
    ylines.insert(y2);
    if (y2 < n) ylines.insert(y2 + 1);
  }
  xlines.insert(1);
  xlines.insert(n + 1);
  ylines.insert(1);
  ylines.insert(n + 1);
  int LEFT = (int)xlines.size();
  int RIGHT = (int)ylines.size();
  for (auto u : xlines) x.push_back(u);
  for (auto u : ylines) y.push_back(u);
  mincost::init(0, LEFT + RIGHT + 1, LEFT + RIGHT + 5);
  long long int value = 0;
  for (int i = 0; i + 1 < LEFT; ++i) {
    int iks = x[i];
    for (int j = 0; j + 1 < RIGHT; ++j) {
      int igr = y[j];
      bool needs = false;
      for (int rect = 1; rect <= m; ++rect) {
        if (X1[rect] <= iks && iks <= X2[rect] && Y1[rect] <= igr &&
            igr <= Y2[rect]) {
          needs = true;
          break;
        }
      }
      if (needs) {
        int kosz = min(x[i + 1] - x[i], y[j + 1] - y[j]);
        mincost::add(i + 1, j + 1 + LEFT, inf, 0);
        value += kosz;
      }
    }
  }
  for (int i = (1); i <= (LEFT - 1); ++i)
    mincost::add(0, i, x[i] - x[i - 1], 0);
  for (int i = (1); i <= (RIGHT - 1); ++i)
    mincost::add(LEFT + i, LEFT + RIGHT + 1, y[i] - y[i - 1], 0);
  mincost::solve();
  cout << mincost::flow;
}