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 INF = (1LL) << 62;
vector<int> adj[202];
int N, M;
long long C[202][202];
long long F[202][202];
int A[202][202];
int X1[55];
int Y1[55];
int X2[55];
int Y2[55];
vector<int> xs;
vector<int> ys;
int X, Y;
int convx(int x) {
  return lower_bound(xs.begin(), xs.end(), x) - xs.begin() + 1;
}
int convy(int y) {
  return lower_bound(ys.begin(), ys.end(), y) - ys.begin() + 1;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; i++) {
    scanf("%d%d%d%d", &X1[i], &Y1[i], &X2[i], &Y2[i]);
    X2[i]++;
    Y2[i]++;
    xs.push_back(X1[i]);
    xs.push_back(X2[i]);
    ys.push_back(Y1[i]);
    ys.push_back(Y2[i]);
  }
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  sort(ys.begin(), ys.end());
  ys.erase(unique(ys.begin(), ys.end()), ys.end());
  for (int i = 1; i <= M; i++) {
    X1[i] = convx(X1[i]);
    X2[i] = convx(X2[i]);
    Y1[i] = convy(Y1[i]);
    Y2[i] = convy(Y2[i]);
  }
  X = xs.size();
  Y = ys.size();
  for (int i = 1; i <= M; i++) {
    for (int j = X1[i]; j < X2[i]; j++) {
      for (int k = Y1[i]; k < Y2[i]; k++) {
        A[j][k] = 1;
      }
    }
  }
  for (int i = 1; i < X; i++) {
    for (int j = 1; j < Y; j++) {
      if (A[i][j]) {
        adj[i].push_back(j + X);
        adj[j + X].push_back(i);
        C[i][j + X] = INF;
      }
    }
  }
  for (int i = 1; i < X; i++) C[0][i] = xs[i] - xs[i - 1];
  for (int i = 1; i < Y; i++) C[X + i][X + Y] = ys[i] - ys[i - 1];
  for (int i = 1; i < X; i++) {
    adj[0].push_back(i);
    adj[i].push_back(0);
  }
  for (int i = 1; i < Y; i++) {
    adj[i + X].push_back(X + Y);
    adj[X + Y].push_back(i + X);
  }
  int S = 0, E = X + Y;
  long long ret = 0;
  while (1) {
    int prev[202];
    for (int i = 0; i < 202; i++) prev[i] = -1;
    queue<int> q;
    q.push(S);
    while (!q.empty() && prev[E] == -1) {
      int now = q.front();
      q.pop();
      for (int i : adj[now]) {
        if (C[now][i] - F[now][i] > 0 && prev[i] == -1) {
          q.push(i);
          prev[i] = now;
          if (i == E) break;
        }
      }
    }
    if (prev[E] == -1) break;
    long long flow = INF;
    for (int i = E; i != S; i = prev[i])
      flow = min(flow, C[prev[i]][i] - F[prev[i]][i]);
    for (int i = E; i != S; i = prev[i]) {
      F[prev[i]][i] += flow;
      F[i][prev[i]] -= flow;
    }
    ret += flow;
  }
  printf("%lld\n", ret);
  return 0;
}