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 M = 55, N = 500, inf = 1e9;
int n, m, X[M * 2], Y[M * 2], e, nx = 0, ny = 0;
struct rectangle {
  int id, x1, x2, y1, y2;
} r[M];
struct edge {
  int to, cap, rev;
};
vector<edge> g[N];
void adde(int u, int v, int w) {
  g[u].push_back((edge){v, w, (int)g[v].size()});
  g[v].push_back((edge){u, 0, (int)g[u].size() - 1});
}
int lev[N], itr[N];
void bfs() {
  memset(lev, -1, sizeof(lev));
  queue<int> Q;
  Q.push(0);
  lev[0] = 0;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = 0; i < (int)g[u].size(); ++i) {
      int v = g[u][i].to;
      if (g[u][i].cap && lev[v] < 0) {
        lev[v] = lev[u] + 1;
        Q.push(v);
      }
    }
  }
}
int dfs(int u, int f) {
  if (u == e) return f;
  for (int &i = itr[u]; i < (int)g[u].size(); ++i) {
    int v = g[u][i].to, r = g[u][i].rev;
    if (lev[v] > lev[u] && g[u][i].cap) {
      int d = dfs(v, min(f, g[u][i].cap));
      if (d) {
        g[u][i].cap -= d;
        g[v][r].cap += d;
        return d;
      }
    }
  }
  return 0;
}
int Max_flow() {
  int flow = 0;
  for (;;) {
    bfs();
    if (lev[e] < 0) return flow;
    memset(itr, 0, sizeof(itr));
    int f = dfs(0, inf);
    while (f) {
      flow += f;
      f = dfs(0, inf);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d%d", &r[i].x1, &r[i].y1, &r[i].x2, &r[i].y2);
    X[++nx] = r[i].x1;
    X[++nx] = ++r[i].x2;
    Y[++ny] = r[i].y1;
    Y[++ny] = ++r[i].y2;
  }
  X[++nx] = Y[++ny] = n + 1;
  sort(X + 1, X + nx + 1);
  sort(Y + 1, Y + ny + 1);
  nx = unique(X + 1, X + nx + 1) - X - 1;
  ny = unique(Y + 1, Y + ny + 1) - Y - 1;
  for (int i = 1; i <= m; ++i) {
    r[i].x1 = lower_bound(X + 1, X + nx + 1, r[i].x1) - X;
    r[i].x2 = lower_bound(X + 1, X + nx + 1, r[i].x2) - X;
    r[i].y1 = lower_bound(Y + 1, Y + ny + 1, r[i].y1) - Y;
    r[i].y2 = lower_bound(Y + 1, Y + ny + 1, r[i].y2) - Y;
  }
  e = nx + ny + 1;
  for (int i = 1; i <= m; ++i) {
    for (int x = r[i].x1; x < r[i].x2; ++x) {
      for (int y = r[i].y1; y < r[i].y2; ++y) {
        adde(x, nx + y, inf);
      }
    }
  }
  for (int i = 1; i < nx; ++i) adde(0, i, X[i + 1] - X[i]);
  for (int i = 1; i < ny; ++i) adde(nx + i, e, Y[i + 1] - Y[i]);
  cout << Max_flow() << endl;
  return 0;
}