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 int maxm = 200 + 10;
struct rect {
  int x1, y1, x2, y2;
  void readin() {
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    x2++;
    y2++;
  }
} a[maxm];
int n, m, src, dst;
vector<int> x, y;
bool b[maxm][maxm];
long long cap[maxm][maxm], ans;
int p[maxm], que[maxm];
bool find_path() {
  int head = 0, tail = 0;
  memset(p, -1, sizeof(p));
  que[tail++] = src;
  p[src] = src;
  while (head < tail) {
    int x = que[head++];
    for (int y = 0; y <= dst; y++) {
      if (cap[x][y] > 0 && p[y] == -1) {
        p[y] = x;
        que[tail++] = y;
      }
    }
  }
  return p[dst] != -1;
}
void push_flow() {
  long long flow = 1LL << 40;
  for (int v = dst; v != src; v = p[v]) {
    flow = min(flow, cap[p[v]][v]);
  }
  ans += flow;
  for (int v = dst; v != src; v = p[v]) {
    cap[p[v]][v] -= flow;
    cap[v][p[v]] += flow;
  }
}
void work() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    a[i].readin();
    x.push_back(a[i].x1);
    x.push_back(a[i].x2);
    y.push_back(a[i].y1);
    y.push_back(a[i].y2);
  }
  x.push_back(1);
  x.push_back(n + 1);
  y.push_back(1);
  y.push_back(n + 1);
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  y.erase(unique(y.begin(), y.end()), y.end());
  for (int i = 0; i < m; i++) {
    int x1 = lower_bound(x.begin(), x.end(), a[i].x1) - x.begin();
    int x2 = lower_bound(x.begin(), x.end(), a[i].x2) - x.begin();
    int y1 = lower_bound(y.begin(), y.end(), a[i].y1) - y.begin();
    int y2 = lower_bound(y.begin(), y.end(), a[i].y2) - y.begin();
    for (int j = x1; j < x2; j++) {
      for (int k = y1; k < y2; k++) {
        b[j][k] = true;
      }
    }
  }
  src = x.size() + y.size() + 1;
  dst = src + 1;
  for (int i = 0; i < x.size() - 1; i++) {
    cap[src][i] = x[i + 1] - x[i];
  }
  for (int j = 0; j < y.size() - 1; j++) {
    cap[x.size() + j][dst] = y[j + 1] - y[j];
  }
  for (int i = 0; i < x.size(); i++) {
    for (int j = 0; j < y.size(); j++) {
      if (b[i][j]) {
        cap[i][x.size() + j] = 1LL << 40;
      }
    }
  }
  while (find_path()) {
    push_flow();
  }
  cout << ans << endl;
}
int main() {
  int TestCase = 1;
  while (TestCase--) {
    work();
  }
  return 0;
}