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 INFLL = LLONG_MAX;
const int INF = INT_MAX;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T> >;
template <class T>
void sort(vector<T>& v) {
  sort(v.begin(), v.end());
}
template <class T, class U>
void sort(vector<T>& v, U func) {
  sort(v.begin(), v.end(), func);
}
template <class T>
int lb_index(vector<T>& v, T k) {
  return lower_bound(v.begin(), v.end(), k) - v.begin();
}
template <class T>
int ub_index(vector<T>& v, T k) {
  return upper_bound(v.begin(), v.end(), k) - v.begin();
}
struct flow {
  int n, s, t;
  struct edge {
    int from, to, cap;
    edge(int f, int t, int c) : from(f), to(t), cap(c) {}
  };
  vector<edge> e;
  vector<vector<int> > v;
  flow(int n, int s, int t) : n(n), s(s), t(t), v(n) {}
  void addedge(int s, int t, int c) {
    v[s].emplace_back(e.size());
    e.emplace_back(s, t, c);
    v[t].emplace_back(e.size());
    e.emplace_back(t, s, 0);
  }
  vector<int> dist, par;
  int minedge;
  int bfs() {
    for (int i = 0; i < n; i++) {
      par[i] = -1;
      dist[i] = INT_MAX;
    }
    dist[s] = 0;
    queue<int> q;
    q.emplace(s);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < v[u].size(); i++) {
        if (e[v[u][i]].cap <= 0) {
          continue;
        }
        if (dist[e[v[u][i]].to] == INT_MAX) {
          dist[e[v[u][i]].to] = dist[u] + 1;
          par[e[v[u][i]].to] = v[u][i];
          q.emplace(e[v[u][i]].to);
        }
      }
    }
    return dist[t];
  }
  int aug() {
    minedge = INT_MAX;
    for (int i = t; par[i] != -1; i = e[par[i]].from) {
      minedge = min(e[par[i]].cap, minedge);
    }
    for (int i = t; par[i] != -1; i = e[par[i]].from) {
      e[par[i]].cap -= minedge;
      e[par[i] ^ 1].cap += minedge;
    }
    return minedge;
  }
  int maxflow() {
    int flowrate = 0;
    for (int i = 0; i < n; i++) {
      par.emplace_back(-1);
      dist.emplace_back(INT_MAX);
    }
    while (bfs() != INT_MAX) {
      flowrate += aug();
    }
    return flowrate;
  }
};
struct dis {
  vector<pair<pair<int, int>, pair<int, int> > > v;
  vector<vector<bool> > c;
  vector<int> lx, ly;
  int n, m;
  dis(vector<pair<pair<int, int>, pair<int, int> > > v) : v(v) {
    map<int, bool> xp, yp;
    vector<int> x, y;
    for (auto i : v) {
      int x1 = i.first.first, y1 = i.first.second, x2 = i.second.first,
          y2 = i.second.second;
      if (!xp[x1 - 1]) x.emplace_back(x1 - 1);
      if (!xp[x2]) x.emplace_back(x2);
      if (!yp[y1 - 1]) y.emplace_back(y1 - 1);
      if (!yp[y2]) y.emplace_back(y2);
      sort(x);
      sort(y);
    }
    n = x.size();
    m = y.size();
    vector<vector<bool> > b(n, vector<bool>(m));
    for (auto i : v) {
      int x1 = lb_index(x, i.first.first), y1 = lb_index(y, i.first.second),
          x2 = lb_index(x, i.second.first), y2 = lb_index(y, i.second.second);
      for (int j = x1; j <= x2; j++) {
        for (int k = y1; k <= y2; k++) {
          b[j][k] = 1;
        }
      }
    }
    c = b;
    lx = x;
    ly = y;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<pair<int, int>, pair<int, int> > > v;
  while (m--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    v.emplace_back(make_pair(a, b), make_pair(c, d));
  }
  dis cc = dis(v);
  n = cc.n;
  m = cc.m;
  flow f(n + m + 2, 0, n + m + 1);
  for (int i = 0; i < n; i++)
    f.addedge(0, i + 1, (i ? cc.lx[i] - cc.lx[i - 1] : cc.lx[0]));
  for (int i = 0; i < m; i++)
    f.addedge(n + i + 1, n + m + 1, (i ? cc.ly[i] - cc.ly[i - 1] : cc.ly[0]));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (cc.c[i][j]) f.addedge(i + 1, n + j + 1, INF);
    }
  }
  cout << f.maxflow();
}