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;
void desperate_optimization(int precision) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}
struct edge {
  int nx;
  int rev;
  int cap;
  int flow;
};
const int INF = 1e9;
const int N = 2000;
vector<edge> lst[N + 5];
int lv[N + 5];
int start[N + 5];
pair<pair<int, int>, pair<int, int> > vec[N + 5];
vector<pair<int, int> > order;
bool cmp(pair<int, int> &A, pair<int, int> &B) {
  if (A.first != B.first) return A.first < B.first;
  return A.second > B.second;
}
map<pair<int, int>, int> ms;
bool isInside(int u, int v, int w, int x) { return u <= w && x <= v; }
void addEdge(int u, int v, int cap) {
  edge tmp, tmp2;
  tmp.nx = v, tmp.rev = lst[v].size(), tmp.cap = cap, tmp.flow = 0;
  tmp2.nx = u, tmp2.rev = lst[u].size(), tmp2.cap = cap, tmp2.flow = cap;
  lst[u].push_back(tmp), lst[v].push_back(tmp2);
}
int id;
queue<int> q;
bool bfs(int SRC, int SNK) {
  for (int i = 0; i <= id; i++) {
    lv[i] = -1;
    start[i] = 0;
  }
  q.push(SRC);
  lv[SRC] = 0;
  while (!q.empty()) {
    int pos = q.front();
    q.pop();
    for (auto x : lst[pos]) {
      if (x.cap == x.flow) continue;
      if (lv[x.nx] != -1) continue;
      lv[x.nx] = lv[pos] + 1;
      q.push(x.nx);
    }
  }
  return lv[SNK] != -1;
}
int dfs(int curr, int tar, int cap) {
  if (curr == tar) return cap;
  int tot = 0;
  for (; start[curr] != lst[curr].size(); start[curr]++) {
    edge &tmp = lst[curr][start[curr]];
    if (lv[tmp.nx] != lv[curr] + 1) continue;
    if (tmp.cap == tmp.flow) continue;
    int flow = min(cap, tmp.cap - tmp.flow);
    int get = dfs(tmp.nx, tar, flow);
    cap -= get;
    tot += get;
    tmp.flow += get;
    lst[tmp.nx][tmp.rev].flow -= get;
    if (cap == 0) return tot;
  }
  return tot;
}
int dinic(int SRC, int SNK) {
  int tot = 0;
  while (bfs(SRC, SNK)) {
    tot += dfs(SRC, SNK, 1e9);
  }
  return tot;
}
void hora(int tc) {
  int n, m;
  cin >> m >> n;
  for (int i = 1; i <= n; i++) {
    pair<int, int> A, B;
    cin >> A.first >> A.second >> B.first >> B.second;
    vec[i] = {A, B};
  }
  int SRC = 0, SNK = n + 1;
  id = n + 1;
  order.clear();
  for (int i = 1; i <= n; i++) {
    order.push_back({vec[i].first.first, 1});
    order.push_back({vec[i].second.first, -1});
  }
  sort(order.begin(), order.end(), cmp);
  int tot = 0;
  int last = 0;
  for (auto x : order) {
    int u = x.first;
    int v = x.second;
    if (tot != 0) {
      if (v == 1) {
        if (last <= u - 1) {
          if (ms[{last, u - 1}] == 0) {
            ms[{last, u - 1}] = ++id;
            addEdge(SRC, id, u - last);
          }
          for (int i = 1; i <= n; i++) {
            int target = ms[{last, u - 1}];
            if (isInside(vec[i].first.first, vec[i].second.first, last, u - 1))
              addEdge(target, i, INF);
          }
        }
      } else {
        if (last <= u) {
          if (ms[{last, u}] == 0) {
            ms[{last, u}] = ++id;
            addEdge(SRC, id, u - last + 1);
          }
          for (int i = 1; i <= n; i++) {
            int target = ms[{last, u}];
            if (isInside(vec[i].first.first, vec[i].second.first, last, u))
              addEdge(target, i, INF);
          }
        }
      }
    }
    tot += v;
    last = u;
    if (v == -1) last++;
  }
  order.clear();
  for (int i = 1; i <= n; i++) {
    order.push_back({vec[i].first.second, 1});
    order.push_back({vec[i].second.second, -1});
  }
  ms.clear();
  sort(order.begin(), order.end(), cmp);
  tot = 0;
  last = 0;
  for (auto x : order) {
    int u = x.first;
    int v = x.second;
    if (tot != 0) {
      if (v == 1) {
        if (last <= u - 1) {
          if (ms[{last, u - 1}] == 0) {
            ms[{last, u - 1}] = ++id;
            addEdge(id, SNK, u - last);
          }
          for (int i = 1; i <= n; i++) {
            int target = ms[{last, u - 1}];
            if (isInside(vec[i].first.second, vec[i].second.second, last,
                         u - 1))
              addEdge(i, target, INF);
          }
        }
      } else {
        if (last <= u) {
          if (ms[{last, u}] == 0) {
            ms[{last, u}] = ++id;
            addEdge(id, SNK, u - last + 1);
          }
          for (int i = 1; i <= n; i++) {
            int target = ms[{last, u}];
            if (isInside(vec[i].first.second, vec[i].second.second, last, u))
              addEdge(i, target, INF);
          }
        }
      }
    }
    tot += v;
    last = u;
    if (v == -1) last++;
  }
  cout << dinic(SRC, SNK) << '\n';
}
int main() {
  desperate_optimization(10);
  int ntc = 1;
  for (int tc = 1; tc <= ntc; tc++) hora(tc);
  return 0;
}