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;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U>
void _W(const pair<T, U> &x) {
  _W(x.first);
  putchar(' ');
  _W(x.second);
}
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
int MOD = 1e9 + 7;
void ADD(long long &x, long long v) {
  x = (x + v) % MOD;
  if (x < 0) x += MOD;
}
const int SIZE = 1e6 + 10;
struct E {
  int k;
  long long c;
  E() {}
  E(int _k, long long _c) : k(_k), c(_c) {}
} es[2000010];
struct Flow {
  int n, m, dis[500010];
  int qq[500010], qr, ql;
  int ptr[500010];
  vector<int> e[500010];
  void init(int _n) {
    n = _n;
    m = 0;
    for (int i = 0; i < n; i++) {
      vector<int> tmp;
      e[i].swap(tmp);
    }
  }
  void add_edge(int a, int b, long long c) {
    e[a].push_back(m);
    es[m] = E(b, c);
    m++;
    e[b].push_back(m);
    es[m] = E(a, 0);
    m++;
  }
  bool BFS() {
    memset(dis, -1, n * sizeof(int));
    ql = qr = 0;
    qq[qr++] = 0;
    dis[0] = 0;
    while (ql != qr && dis[n - 1] == -1) {
      int p = qq[ql++];
      for (auto &it : e[p]) {
        E ee = es[it];
        if (ee.c == 0 || dis[ee.k] != -1) continue;
        dis[ee.k] = dis[p] + 1;
        qq[qr++] = ee.k;
      }
    }
    return dis[n - 1] != -1;
  }
  long long go(int p, long long c) {
    if (p == n - 1) return c;
    long long ret = 0, tmp;
    for (int &i = ptr[p]; i < ((int)(e[p]).size()); i++) {
      auto it = e[p][i];
      E &ee = es[it];
      if (ee.c == 0 || dis[p] + 1 != dis[ee.k]) continue;
      tmp = go(ee.k, min(c - ret, (long long)ee.c));
      ret += tmp;
      ee.c -= tmp;
      es[it ^ 1].c += tmp;
      if (ret == c) break;
    }
    if (ret == 0) dis[p] = -1;
    return ret;
  }
  long long maxflow() {
    long long ret = 0;
    while (BFS()) {
      memset(ptr, 0, n * sizeof(int));
      ret += go(0, 1LL << 60);
    }
    return ret;
  }
} flow;
int x[51][2], y[51][2];
int a[121][121];
int main() {
  int n, m;
  R(n, m);
  if (!m) {
    W(0);
    return 0;
  }
  vector<int> xx, yy;
  for (int i = 0; i < (m); ++i) {
    R(x[i][0], y[i][0], x[i][1], y[i][1]);
    xx.emplace_back(x[i][0]);
    xx.emplace_back(x[i][1] + 1);
    yy.emplace_back(y[i][0]);
    yy.emplace_back(y[i][1] + 1);
  }
  (sort(xx.begin(), xx.end()),
   xx.resize(distance(xx.begin(), unique(xx.begin(), xx.end()))));
  (sort(yy.begin(), yy.end()),
   yy.resize(distance(yy.begin(), unique(yy.begin(), yy.end()))));
  for (int k = 0; k < (m); ++k) {
    int st_i = (lower_bound(xx.begin(), xx.end(), x[k][0]) - xx.begin()) + 1,
        ed_i =
            (lower_bound(xx.begin(), xx.end(), x[k][1] + 1) - xx.begin()) + 1;
    int st_j = (lower_bound(yy.begin(), yy.end(), y[k][0]) - yy.begin()) + 1,
        ed_j =
            (lower_bound(yy.begin(), yy.end(), y[k][1] + 1) - yy.begin()) + 1;
    for (int i = (st_i); i < (ed_i); ++i)
      for (int j = (st_j); j < (ed_j); ++j) {
        a[i][j] = 1;
      }
  }
  flow.init(((int)(xx).size()) + ((int)(yy).size()));
  for (int i = (1); i < (((int)(xx).size())); ++i)
    flow.add_edge(0, i, xx[i] - xx[i - 1]);
  for (int i = (1); i < (((int)(yy).size())); ++i)
    flow.add_edge(((int)(xx).size()) + i - 1, flow.n - 1, yy[i] - yy[i - 1]);
  for (int i = (1); i < (((int)(xx).size())); ++i)
    for (int j = (1); j < (((int)(yy).size())); ++j) {
      if (a[i][j])
        flow.add_edge(i, ((int)(xx).size()) + j - 1, 1000000000000000LL);
    }
  W(flow.maxflow());
  return 0;
}