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;
inline int add(int _a, int _b) {
  if (_a < 0) {
    _a += 1000000007;
  }
  if (_b < 0) {
    _b += 1000000007;
  }
  if (_a + _b >= 1000000007) {
    return _a + _b - 1000000007;
  }
  return _a + _b;
}
inline int mul(int _a, int _b) {
  if (_a < 0) {
    _a += 1000000007;
  }
  if (_b < 0) {
    _b += 1000000007;
  }
  return ((long long int)((long long int)_a * (long long int)_b)) % 1000000007;
}
struct edge {
  int dest, back;
  long long int f, c;
  edge(int d, int b, long long int f, long long int c)
      : dest(d), back(b), f(f), c(c) {}
};
struct push_relabel {
  vector<vector<edge> > g;
  vector<long long int> ec;
  vector<edge*> cur;
  vector<vector<int> > hs;
  vector<int> H;
  push_relabel(int n) : g(n), ec(n), cur(n), hs(n + n), H(n) {}
  void add_edge(int s, int t, long long int cap, long long int rcap = 0) {
    if (s == t) return;
    g[s].emplace_back(t, g[t].size(), 0, cap);
    g[t].emplace_back(s, g[s].size() - 1, 0, rcap);
  }
  void add_flow(edge& e, long long int f) {
    edge& back = g[e.dest][e.back];
    if (!ec[e.dest] && f) hs[H[e.dest]].emplace_back(e.dest);
    e.f += f, e.c -= f, ec[e.dest] += f;
    back.f -= f, back.c += f, ec[back.dest] -= f;
  }
  long long int max_flow(int s, int t) {
    int v = g.size(), i, j;
    H[s] = v, ec[t] = 1;
    vector<int> co(v + v);
    co[0] = v - 1;
    for (i = 0; i < v; i++) cur[i] = g[i].data();
    for (auto& e : g[s]) add_flow(e, e.c);
    for (int hi = 0;;) {
      while (hs[hi].empty())
        if (!hi--) return -ec[s];
      int u = hs[hi].back();
      hs[hi].pop_back();
      while (ec[u] > 0) {
        if (cur[u] == g[u].data() + g[u].size()) {
          H[u] = 1e9 + 5;
          for (auto& e : g[u])
            if (e.c && H[u] > H[e.dest] + 1) H[u] = H[e.dest] + 1, cur[u] = &e;
          if (++co[H[u]], !--co[hi] && hi < v) {
            for (i = 0; i < v; i++)
              if (hi < H[i] && H[i] < v) --co[H[i]], H[i] = v + 1;
          }
          hi = H[u];
        } else if (cur[u]->c && H[u] == H[cur[u]->dest] + 1)
          add_flow(*cur[u], min(ec[u], cur[u]->c));
        else
          ++cur[u];
      }
    }
  }
};
const int N = 50;
struct RECT {
  int x1, x2, y1, y2;
  RECT() {}
  RECT(int _x1, int _x2, int _y1, int _y2) {
    x1 = _x1, x2 = _x2, y1 = _y1, y2 = _y2;
  }
} rect[N + 5];
int n, m;
void solve() {
  int i, j, k, x1, x2, y1, y2;
  if (m == 0) {
    printf("%d", 0), puts("");
    return;
  }
  vector<int> vec_x, vec_y;
  for (i = 0; i < m; i++) {
    vec_x.push_back(rect[i].x1), vec_x.push_back(rect[i].x2);
    vec_y.push_back(rect[i].y1), vec_y.push_back(rect[i].y2);
  }
  sort(vec_x.begin(), vec_x.end());
  sort(vec_y.begin(), vec_y.end());
  vec_x.erase(unique(vec_x.begin(), vec_x.end()), vec_x.end());
  vec_y.erase(unique(vec_y.begin(), vec_y.end()), vec_y.end());
  push_relabel algo(vec_x.size() + vec_y.size());
  int offst = (int)vec_x.size();
  for (i = 0; i + 1 < vec_x.size(); ++i) {
    x1 = vec_x[i], x2 = vec_x[i + 1];
    algo.add_edge(0, i + 1, (long long int)(x2 - x1));
  }
  for (i = 0; i + 1 < vec_x.size(); ++i)
    for (j = 0; j + 1 < vec_y.size(); ++j)
      for (k = 0; k < m; k++) {
        x1 = vec_x[i], x2 = vec_x[i + 1];
        y1 = vec_y[j], y2 = vec_y[j + 1];
        if (x1 >= rect[k].x1 && x2 <= rect[k].x2 && y1 >= rect[k].y1 &&
            y2 <= rect[k].y2) {
          algo.add_edge(i + 1, offst + j,
                        (long long int)(x2 - x1) * (long long int)(y2 - y1));
          break;
        }
      }
  for (i = 0; i + 1 < vec_y.size(); ++i) {
    y1 = vec_y[i], y2 = vec_y[i + 1];
    algo.add_edge(offst + i, (int)vec_x.size() + (int)vec_y.size() - 1,
                  (long long int)(y2 - y1));
  }
  long long int flow =
      algo.max_flow(0, (int)vec_x.size() + (int)vec_y.size() - 1);
  printf("%lld", flow), puts("");
}
int main() {
  int i, j;
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d", &rect[i].x1, &rect[i].y1);
    scanf("%d %d", &rect[i].x2, &rect[i].y2);
    rect[i].x1--, rect[i].y1--;
  }
  solve();
}