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;
int n, m;
int daoskdoa[51], aodksao[51], dksaopdoa[51], dosakdosa[51];
vector<int> x, y;
struct edge {
  int to, cap, rev;
};
int V;
vector<edge> G[2005];
int level[2005];
int iter[2005];
void add_edge(int from, int to, int cap) {
  G[from].push_back((edge){to, cap, (int)G[to].size()});
  G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}
void bfs(int s) {
  memset(level, -1, sizeof(level));
  queue<int> que;
  level[s] = 0;
  que.push(s);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int i = 0; i < (int)G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[e.to] < 0) {
        level[e.to] = level[v] + 1;
        que.push(e.to);
      }
    }
  }
}
int dfs(int v, int t, int f) {
  if (v == t) return f;
  for (int &i = iter[v]; i < (int)G[v].size(); i++) {
    edge &e = G[v][i];
    if (level[v] < level[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s, int t) {
  int flow = 0;
  for (;;) {
    bfs(s);
    if (level[t] < 0) return flow;
    memset(iter, 0, sizeof(iter));
    int f;
    while ((f = dfs(s, t, 1000000000)) > 0) flow += f;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d%d", &daoskdoa[i], &dksaopdoa[i], &aodksao[i], &dosakdosa[i]);
    aodksao[i]++;
    dosakdosa[i]++;
    x.push_back(daoskdoa[i]);
    x.push_back(aodksao[i]);
    y.push_back(dksaopdoa[i]);
    y.push_back(dosakdosa[i]);
  }
  sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  sort(y.begin(), y.end());
  y.erase(unique(y.begin(), y.end()), y.end());
  V = (int)x.size() + (int)y.size();
  int s = (int)x.size() + (int)y.size() - 1, t = (int)x.size() + (int)y.size();
  for (int i = 1; i < (int)x.size(); i++) add_edge(s, i, x[i] - x[i - 1]);
  for (int i = 1; i < (int)y.size(); i++)
    add_edge(i + (int)x.size() - 1, t, y[i] - y[i - 1]);
  for (int i = 0; i < m; i++) {
    int l1 = lower_bound(x.begin(), x.end(), daoskdoa[i]) - x.begin(),
        r1 = lower_bound(x.begin(), x.end(), aodksao[i]) - x.begin();
    int l2 = lower_bound(y.begin(), y.end(), dksaopdoa[i]) - y.begin(),
        r2 = lower_bound(y.begin(), y.end(), dosakdosa[i]) - y.begin();
    for (int i = l1 + 1; i <= r1; i++)
      for (int j = l2 + 1; j <= r2; j++)
        add_edge(i, (int)x.size() - 1 + j, 1000000000);
  }
  printf("%d\n", max_flow(s, t));
  return 0;
}