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;
vector<vector<int>> capa, adj;
int si;
int tot;
bool bfs(int s, int t) {
  queue<int> q;
  vector<int> parent(si, -1);
  q.push(s);
  parent[s] = s;
  while (!q.empty()) {
    int i = q.front();
    q.pop();
    for (int j : adj[i]) {
      if (capa[i][j] > 0 && parent[j] == -1) {
        q.emplace(j);
        parent[j] = i;
        if (j == t) {
          int c = INT_MAX;
          for (int x = parent[t], y = t; y != s; y = x, x = parent[x]) {
            c = min(capa[x][y], c);
          }
          tot += c;
          for (int x = parent[t], y = t; y != s; y = x, x = parent[x]) {
            capa[x][y] -= c;
            capa[y][x] += c;
          }
          return true;
        }
      }
    }
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> x1(m), x2(m), y1(m), y2(m);
  vector<int> x, y;
  for (int i = 0; i < m; i++) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    x.push_back(x1[i] - 1);
    x.push_back(x2[i]);
    y.push_back(y1[i] - 1);
    y.push_back(y2[i]);
  }
  sort(begin(x), end(x));
  sort(begin(y), end(y));
  x.resize(unique(begin(x), end(x)) - begin(x));
  y.resize(unique(begin(y), end(y)) - begin(y));
  int r = x.size() - 1;
  int c = y.size() - 1;
  si = r + c + 2 + m;
  int s = 0, t = si - 1;
  capa.resize(si, vector<int>(si, 0));
  adj.resize(si);
  tot = 0;
  for (int i = 0; i < r; i++) {
    capa[s][i + 1] = x[i + 1] - x[i];
    adj[s].push_back(i + 1);
    adj[i + 1].push_back(s);
  }
  for (int i = 0; i < c; i++) {
    capa[r + m + 1 + i][t] = y[i + 1] - y[i];
    adj[r + m + i + 1].push_back(t);
    adj[t].push_back(r + m + i + 1);
  }
  for (int i = 0; i < m; i++) {
    int l1 = lower_bound(begin(x), end(x), x1[i]) - begin(x);
    int l2 = lower_bound(begin(x), end(x), x2[i]) - begin(x);
    l1--, l2--;
    for (int j = l1; j <= l2; j++) {
      capa[j + 1][r + 1 + i] = INT_MAX;
      adj[j + 1].push_back(r + i + 1);
      adj[r + i + 1].push_back(j + 1);
    }
    l1 = lower_bound(begin(y), end(y), y1[i]) - begin(y);
    l2 = lower_bound(begin(y), end(y), y2[i]) - begin(y);
    l1--, l2--;
    for (int j = l1; j <= l2; j++) {
      capa[r + 1 + i][r + m + 1 + j] = INT_MAX;
      adj[r + 1 + i].push_back(r + m + 1 + j);
      adj[r + m + 1 + j].push_back(r + i + 1);
    }
  }
  while (bfs(s, t))
    ;
  cout << tot << endl;
  return 0;
}